Jump to content

How to simulate/generate hardcoded argument to Run NSAppleScript?

Recommended Posts

Hi all,


I've got a seemingly basic question but couldn't find an answer anywhere. I'm currently using a workflow to move the currently selected files in Finder to the folder specified via keyword argument. It's a simple workflow with two components: [Keyword Input]  --> [Run NSAppleScript]. My question is this: how do I pass a hardcoded value/string as an argument to Run NSAppleScript for frequently used destination folders?


I could obviously copy the Run NSAppleScript component and replaced all instances of "q" in the script with the hardcoded folder, but I suspect there's a better way which avoids code duplication. I thought the "Arg and Vars" utility might be relevant here, but it doesn't seem able to generate an argument to pass on to downstream components. Has anyone else encountered a need for this before? Any help would be much appreciated!

Link to comment



Thanks for the reply. I read your [HOW TO] Workflow/environment variables, but am still unsure of how to pass workflow variables to the {query} or argv input of a Run Script action. I know I can access them directly within the script with {var:varname}, but I want to use the same Run Script action with both my Keyword input and my hardcoded input value.


Also, substituting Run Script for Run NSAppleScript doesn't seem to work with my Keyword input either. I removed the "on alfred_script(q)", wrapped the script with "on run" and "end run", and replaced instances of "q" with argv / {query}. I noticed that Run NSAppleScript runs in Alfred's main thread and Run Script doesn't. Not sure if I'm getting the syntax wrong or if this script (moving files around) requires Alfred's main thread.


Thanks again for the help!

Link to comment

Good call - uploaded here. The bottom Run NSAppleScript includes the hardcoded folder that I'm trying to pass in as an argument to the parameterized version of the script. Essentially, I just want one Run NSAppleScript (or Run Script) action with different keyword inputs corresponding to various parameter values for q in  that alfred_script(q). Let me know if I should provide any additional clarification. 

Link to comment
13 hours ago, rahuja said:

I know I can access them directly within the script with {var:varname}


You can't. Only {query} works in the Script box. {var:varname} only works in other Alfred elements like Args and Vars or Filter utilities. You have to use system attribute in AppleScript, as described in the HOWTO.


I'm not exactly clear on what your question is.


If you want to pass a hardcoded value to your dynamically-configured script, put an Args and Vars utility before it and set the query to your path.

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...