External Javascript File Support

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

External Javascript File Support 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.
charlez
 
Posts: 3
Joined: Tue Oct 23, 2018 10:30 am

Re: External Javascript File Support 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.
Mr_Noodle
Site Admin
 
Posts: 11235
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: External Javascript File Support 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.
charlez
 
Posts: 3
Joined: Tue Oct 23, 2018 10:30 am

Re: External Javascript File Support Tue Oct 23, 2018 11:24 am • by Mr_Noodle
Are you using the Run JavaScript action?
Mr_Noodle
Site Admin
 
Posts: 11235
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: External Javascript File Support Tue Oct 23, 2018 11:43 am • by charlez
Yes
charlez
 
Posts: 3
Joined: Tue Oct 23, 2018 10:30 am

Re: External Javascript File Support Wed Oct 24, 2018 10:44 am • by Mr_Noodle
Does it work if you paste the script into Hazel?
Mr_Noodle
Site Admin
 
Posts: 11235
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support