Jump to content

Passing workflow variables to a script filter

Recommended Posts



I am using Alfred 4 along with a custom python script filter that utilizes mdfind to search our company's file shares that are hosted over AFP on a Windows server via a third party tool (Acronis File Connect). Alfred file filters cannot tap into the emulated spotlight index, likely for some good reason that is beyond me, and so with some kind advice from the Alfred team, I went this way instead with a custom implementation of mdfind.


The script filter works great and the results show in Alfred as expected.


My question is: is it possible to pass a workflow variable via the args/vars utility to a script filter?


The reason is: We now need to replace each file filter with a script filter. ATM, that means hardcoding the search scope into the script filter. I would prefer to pass the search scope to the script filter via an upstream variable. I considered Workflow Environment Variables in lieu of the args/var utility, but that got messy quick.


Any advice will be greatly appreciated. One consideration was loading a workflow env variable with key value pairs, casting that to json in the script, and pulling the entry where key = script filter keyword. That seems beefy and I wanna avoid slowing down the script where possible.

Edited by Robert Hartshorn
Link to comment
3 hours ago, Robert Hartshorn said:

 Is it possible to set the var in args/vars before I hit the script filter?


Not if the Script Filter is your entry point (i.e. you call it via its own keyword). To set dynamic variables (the ones in the workflow config sheet are always set), you'd have to use a Keyword or Hotkey to run the workflow and set the variables after that but before the Script Filter.

Link to comment
  • 6 months later...

I wanted to double check that I got this correctly: If I have a file filter in my workflow and I want the user to set the scope in the workflow variables in the config sheet, the only way to launch that file filter is by using a keyword (so an extra ↩️)) or a hotkey, followed by a JSON Config object? 

Link to comment

1) I often have more than one such file filter in a single workflow and it would be more efficient to change only once, 2) it sounds easier for users who might not be familiar with the process and 3) in general I was curious about the way changing file filter options works.


Link to comment
3 hours ago, giovanni said:

the only way to launch that file filter is by using a keyword (so an extra ↩️)) or a hotkey, followed by a JSON Config object?


Pretty much, yeah. A JSON Config is the only official way to dynamically-configure a File Search's scope.


Unofficially, you could add a second File Filter to configure the search scope (instead of setting a workflow variable), and edit the File Filter’s scope directly in info.plist.

Link to comment
Posted (edited)

Here's a demonstration workflow that reconfigures a File Filter's scope by editing info.plist.


Keyword dynsearch is the main “search” File Filter, and keyword dynset lets you change the scope of the main File Filter. Instead of storing a workflow/environment variable, it edits the File Filter config in info.plist, so you don’t need the extra Keyword and JSON Config.


As the File Filter’s UID is hard-coded in the script (dynamic.py), you have to be careful not to delete the main File Filter (or to update the script with the new UID if you do).

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