Jump to content

Variables confusion, Arg & Vars?

Recommended Posts



I was looking at my workflow and eventually figured out why one part is slow. I have a script filter that first finds the front most app and then gets the open file. I realized that is running on each execution of the script filter when it doesn't need to. I thus separated it into an intermediary run script action. How do I pass that file path as a variable? I'm not sure if Arg and Vars can be used in this case, accessing the variable thus from the next step of an AppleScript script filter. Alternatively, I can save the file as an environment variable using:

set bundleID to (system attribute "alfred_workflow_bundleid")
tell application "Alfred 3"
    set configuration "…" to value quoted form of theFile in workflow bundleID with exportable
end tell

but then the variable becomes a permanent setting, saved with the workflow plist. Unneeded plus if I wanted to not have that always show up as a git change, I'll have to add some file filter to ignore that line. Is what is set by Arg and Vars accessible by later AppleScript scripts and script filters? 

Edited by h2ner
Link to comment

@h2ner if you pass some text out of a Run Script (i.e. the open file you've looked up), then it can be set to a variable in the Arg & Var (set the name of the variable, and set the value to {query}). The variable is then available to subsequent scripts (i.e. the Script Filter) as an environment variable.


As you've said, this is a much cleaner way than adding some configuration.




Link to comment

Hello Andrew,


When I tried an Arg and Vars step after Run Script, which as you suggested sets an environment variable from {query}, in the next step of a Script Filter, {query} and argv are also set to the value from the Run Script (return … [to {query}]). Perhaps I'm missing something? The Script Filter should run with argv as whatever is the input text of the Script Filter, with the variable additionally available. So far, I'm only able to get that from the above mentioned AppleScript within the Run Script. I make use of the variable only during execution of the workflow – no need for it to be saved afterwards –, and am thus not sure if there's another way, or if within the Script Filter, some alternate code is needed. I don't remember if it was mentioned in the docs, are variables set permanently or is there a way to set variables to be available only during script execution and thus aren't saved to the plist? If they are permanent, perhaps then there's some step I can add at the end which will remove the variable from the environment.

Link to comment



port of Gnosis to Go. setup code for creating database, etc. not included but if having run Gnosis at least once, moving the db to the workflow folder as jnana.db and it should work.


I reread your variable docs deanishe and figured it out. I didn't have a step at the end that deleted the variable; had thought that if it wasn't exportable, it would automatically disappear and not show up in the variable list. Perhaps it's there in the wording somewhere.


Having added the step of saving a variable through AppleScript, it seems there's a noticeable delay which may be the step of retrieving the variable. Where I need a variable, for filtering items according to the open file, that SQLite query is more complex and seems like it can take up at least 20+ more ms; could be both combined that make that querying items for the currently opened file seem slightly slower than a FTS query on the whole database.


It seems like Arg and Vars is then not appropriate for use before a Script Filter action? Arg and Vars seems to automatically pass the variable as query or argv to the following script filter. Or maybe there's another way to set it up. As the workflow is in general pretty fast in Go, any slightly delay I'm starting to notice.

Link to comment
6 hours ago, h2ner said:

Perhaps it's there in the wording somewhere.


The section on Saving variables?


6 hours ago, h2ner said:

Arg and Vars seems to automatically pass the variable as query or argv


It does. It automatically puts {query} in the Argument box. If you don't want an argument set, just delete {query} from the box.


6 hours ago, h2ner said:

it seems there's a noticeable delay which may be the step of retrieving the variable


No. Saving variables takes time. Retrieving them shouldn't take any time unless you're doing something daft like reading info.plist yourself.

Edited by deanishe
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...