Tinderbox Forum

Macros - GUI location?

aTbRef8 is very good on the use of Macros, and they are quickly located in the XML tags of a .tbx file, but can I just check that I’m not missing something in my search for them in the GUI ?

I can find a Macro panel on the HTML Inspector – but the (only?) reference to their GUI location and creation that I can find (nothing obvious in the Help file or in the Tinderbox Way) is the following passage in aTbRef8:

Macros can be copied from one Tinderbox file to another by dragging a macro from the source file’s Attributes Macros pane onto a destination file’s View window(s) or Macros pane.

A couple of questions, to make sure that I’ve got it:

  • Is the ‘Attributes Macros pane’ referred to above the one that I have found on the HTML Inspector ?
  • If so, is the dragging of macros (between tbx files) a one by one process, or can we do it in bulk, if we have a number of macros ?
  • Is age getting the better of me ? Have I completely missed something a bit obvious in the docs or GUI ? (Wouldn’t surprise me)

The ‘couple of questions’ and three bullets above remind me of the time-worn observation that there are basically three types of economist:

  • Those who can count,
  • and those who can’t.

Macros are either added to export code within a template or the body of a note, or in action code in an agent or a Rule or (I think) Edict or Stamp. (Macros precede Edicts in the timeline of Tinderbox feature evolution so you’d need to check that.)

IOW, macros are like any other action code, and you enter them in places where you would enter action or export tags.

1 Like

Thanks - so if I’ve understood correctly, when aTbRef speaks of ‘having’ a named macro, for example:

if we have a macro called "Petshop" whose value is simply: $1

Then ...

the HTML inspector is indeed the place in which names are given to macro definitions ?

Yes. Macros can be created, (edited), deleted in the Macro inspector located in the HTML Inspector.

1 Like

It is a little confusing because normally the HTML Inspector refers to just the selected note, but the Macro tab applies to the document overall.

Further to answers above…

Yes, in v6+ macros moved to the Macros tab of the HTM L Inspector.

Just tested and I’m pretty sure that drag/drop method died with v5. Testing in v8.2.3 I can’t drag a functioning macro between 2 docs. Best workaround, copy the code of the desired macro, switch doc focus and Inspector follows focus. make a new macro with the desired name then paste in the copied code.

No. I’ll report this for the manual. My authorial role aside, aTbRef is generally more up do date on where features are but I’m embarrassed that even there I tend to overlook changes. aTbRef8 describes both the Inspector UI for macros and separately what macros are. But the two aren’t cross-linked but will be shortly.

It is worth bearing in mind, as @PaulWalters has noted that macros evolved early in the app’s history as an export code feature and only later became accessible as an action code feature too. Although the examples I give in aTbRef are for writing HTML that is not the only method. Noting they take inputs and so may look like a function wrapper, I suspect that is interesting lightly or untested territory.

1 Like

Both the Macros note and the HTML Inspector Macro tab\ note in aTbRef8 are corrected and cross-linked. In the latter I have removed the out of date reference to dragging macros between files, a feature which was supported only up to v5.x.

1 Like

drag/drop

I might try a quick experiment this weekend with building an XML pasteboard (xquery over active tbx file) to see if a copy-paste Keyboard Maestro macro can be written

The Tinderbox Help gives some description of macros in Help article Export -> Macros -> Export Templates, heading ‘Macros’. The example there is a bit flawed as ^do(disclaimer, show, contact, phone)^ implies there are 3 input parameters, which if used would appear in the macro as $1, $2, $3 (the first parameter is simply the name of the macro. So if we amend the Help examples code to:

<h3>DISCLAIMER</h3>

<p>These notes regard production plans for the $1, a projected production of Imaginary Studios, Inc. All plans are preliminary and strictly confidential. Writers are cautioned that all details are subject to change, and that final budgets are not approved until signed by $2. If you have questions, please call $2 at $3. </p>

The actual use would then look like this, if placed in a note’s $Text or in an export template:

^do(disclaimer, "AGM", "Peter Brown", "07980 123456")^ 

or the same marco as action code, in a stamp like this:

$Text = $Text + "\n" + do(disclaimer, "AGM", "Peter Brown", "07980 123456");

Either way this would insert the following into the exported page (export code) or a note’s $Text (action code):

<h3>DISCLAIMER</h3>

<p>These notes regard production plans for the AGM, a projected production of Imaginary Studios, Inc. All plans are preliminary and strictly confidential. Writers are cautioned that all details are subject to change, and that final budgets are not approved until signed by Peter Brown. If you have questions, please call Peter Brown at 07980 123456.</p>

Note that
Macros aren’t covered in either of the Tinderbox Help menu’s tutorial PDFs (in fairness they are a bit niche).

1 Like

Many thanks for taking the time to find and edit that (as well as for atbRef and your new edits there)

Looking forward to exploring the eval+do combination …

Note that both stamps and macros can be called inline in action code. But also, if macro ‘square’ has code $1 * $1, then code like:

eval(do(square,$MyNum)

will output the square of $MyNum. That said, a simpler action for the same is:

eval($MyNum * $MyNum)

though action code has a power function, so to square $MyNum:

eval(pow($MyNum,2));
1 Like

And of course one obvious expansion allows for things like:

$Text=eval(do(js, "[1,2,3,4,5].map(x=>2*x)"))

where the js macro is defined as:

runCommand('osascript -l JavaScript -e "$1"')
2 Likes

Wow!

You are JavaScriptifying Tinderbox. Great!

:slight_smile: and of course, one could experiment with variants along the lines of:

$MyList="1;2;3;4;5".replace(';', ',');

$Text=eval(do(map, "2 * x", $MyList))

Generating:

2, 4, 6, 8, 10

where the map macro is defined as:

runCommand('osascript -l JavaScript -e "[$2].map(x => $1)"')
1 Like

:thinking:

I’d guess, that you are building a little macro library right now…

1 Like

Perhaps the most basic – in terms of which we could even write map, is fold (a collapsed value, like a sum or product or concatenation etc defined by accumulation – leftward or rightward – over a list, beginning with a seed value)

A left fold for example, (foldl, or reduce, rather than foldr or reduceRight)

$MyList="1;2;3;4;5".replace(';', ',');

$Text=eval(do(foldl, "a * x", 7, $MyList))

Yields (7 * 1 * 2 * 3 * 4 * 5) = 840

Where the macro foldl is defined as:

runCommand('osascript -l JavaScript -e "[$3].reduce((a, x) => $1, $2)"')
1 Like