Jump to content

How to execute javascript applescript from a file?

Recommended Posts



Newbie here


In a new workflow, I want to execute javascript flavored applescript saved in a local .scpt file


Not clear to me which of the menu options I should use: osascript as/js or external script file, or something else.  

And where is the best place to store the file, and how to correctly set the path to it. I opened some sample workflows and saw quite confusing examples, eg calling 'osascript' when using bash with input as argv


Any help much appreciated!

Link to comment

The one with JS in the name is the one for JavaScript, but that only works for code pasted in the Script box. To run an external script, you either need to use the

External Script option or use /bin/bash and call osascript from there.


Your script goes in the workflow directory. That’s the working directory when Alfred runs the workflow, so the path to your script is./my-script.


1 hour ago, korpw8er said:

calling 'osascript' when using bash with input as argv


That's just treating Alfred's Script box like a shell. That's how you need to run your script because an .scpt file is a compiled script, not text, so it can't be executed directly.


To run it, you need to select /bin/bash (or /bin/zsh) and put code like /usr/bin/osascript scriptname.scpt "$1" in the Script box.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...