0
votes

Is it possible to watch folders with a JXA script on Mac?

I am trying to figure out how to detect a folder was opened and run a JXA script. Apple has a javascript version of most things in their guide, but not this page: https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/WatchFolders.html#//apple_ref/doc/uid/TP40016239-CH39-SW1

1

1 Answers

0
votes

It does not appear to be possible to use a JXA script directly as a folder action, but there is an answer on Stack Overflow here which works around the issue by wrapping the JXA script in an Automator workflow.

The scripting dictionary for StandardAdditions defines the folder action handlers, and if you use Script Editor to view the StandardAdditions dictionary with the JavaScript language selected, it looks like the JXA handler should be named like:

function openingFolder(folder)

...but sadly, that function is not invoked when the folder is opened. I could not get any of the defined folder action handlers to be invoked in a JXA script.