This is my first smart rule that uses JXA.
With lots of help from @chrillek I have a complex JXA script that runs perfectly when embedded within the smart rule.
I would prefer to have the script be loaded from an external file but ran into issues when adding my script to the ~/Library/Application Scripts/com.devon-technologies.think/Smart Rules folder.
I first tried to add a sub directory, but that wasn’t recognized in the drop down in the Smart Rule editor.
Fair enough, so I added my script at the top level with the other scripts already there, using a prefix to visually separate my script from the others.
I tried adding the .js file, containing the working code used in the in-line version of the smart rule, but that file didn’t show up in the menu.
Next, I manually changed the suffix from .js to .scpt, then the file showed in the menu, but quickly produced an error on performSmartRule (A "/" can’t go here.) which I believe indicates that DEVONthink is running this as an AppleScript.
Finally, I took the script and compiled it into a scpt file in Script Editor with the language set to JavaScript, and … that works as an external file from a smart rule!
When I look at this file in BBEdit, it has some non-ascii characters at the end of the file and that seems to contain the magic sauce.
Can someone please tell me if this is the only workflow to get a JXA script with a .js file type to load externally from the Smart Rules folder.
