Kind of a general question, more about "why" to code things a particular way, but also a specific "how". What sorts of things do you do with the built-in macros rather than Javascript? I'm trying to gain understanding of each, but don't really get how they fit together.
Are macros only for HFS events, whereas Javascript is necessary for button onclick handling? Is it possible to mix them? Are there pluses and minuses to either approach? Can I trigger an HFS event from a Javascript button click handler?
I'm currently reading through the docs and the standard template code, and exploring how to modify it in some simple ways. As an example, I want to make a custom version of rename, to process a list of specific file names in a particular way; we will change only a few ID character positions of each file name, so we can process a batch in one go.
When I read the scripting commands page, I found the rename macro:
{.rename | A | B.}
which renames the file A to B. I assumed I'd be using this macro for each file in my list, as well as .cut and .set and all to build the new file names.
I'd also like to change each file's timestamp to the current time when it is renamed, which I was thinking to do via {.exec| touch <filename>.}, but it is not clear how to blend macro functions in with Javascript actions.
However, the built-in "Rename" button handler does it in pure Javascript instead, e.g.:
[...some setup code ommitted...]
ezprompt(
this.innerHTML,
{"type":"text", "default":getItemName(a[0])},
function(s){ajax("rename", {from:getItemName(a[0]), to:s});}
);
Is this just because it is the event handler for the button, or are there other reasons to use Javascript rather than macros? Not clear to me how or if it is possible to mix macros and Javascript functions; when do macros "execute" with respect to the Java script functions on the page?
Is there any way to get at the {.exec .} macro from within a click handler for rename? Or, conversely, is there any way to have Javascript run commands on files on the host system? (I've only used Javascript in client side code, which is restricted from such access by the browser.)
Thanks for any general light you can shed!
Steve