Page 1 of 1

External Javascript File Support

PostPosted: Tue Oct 23, 2018 10:58 am
by charlez
I am trying to run an external Javascript file as part of an action.
When I try to choose the .js file that contains my script, it is not selectable.
Are external .js files supported? The documentation references only .scpt files.

Re: External Javascript File Support

PostPosted: Tue Oct 23, 2018 11:01 am
by Mr_Noodle
Is this a pure Javascript script or is this an AppleEvents script using the Javascript language?

If the former, you would want to use the "Run shellscript" action and specify the appropriate JavaScript interpreter on your system as the shell.

If the latter, you need to edit it in an AppleScript editor and save it as a .scpt file. Note that JavaScript is just the language here but it and AppleScript are compiled down to a script of AppleEvents.

Re: External Javascript File Support

PostPosted: Tue Oct 23, 2018 11:11 am
by charlez
Thanks for the clarification!

I tried saving my javascript as a .scpt file, but after choosing that script for execution, I get an error:

"Script is not valid; Please fix the script or try another one."

The script just contains the function from the docs:
Code: Select all
function hazelProcessFile(theFile, inputAttributes)
{

  return { hazelOutputAttributes: ["hello"] }

}


Thanks for the idea of running a shell script; I'll follow that route.

Re: External Javascript File Support

PostPosted: Tue Oct 23, 2018 11:24 am
by Mr_Noodle
Are you using the Run JavaScript action?

Re: External Javascript File Support

PostPosted: Tue Oct 23, 2018 11:43 am
by charlez
Yes

Re: External Javascript File Support

PostPosted: Wed Oct 24, 2018 10:44 am
by Mr_Noodle
Does it work if you paste the script into Hazel?