Robert Hartshorn Posted October 6, 2020 Share Posted October 6, 2020 (edited) Hello, 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 October 6, 2020 by Robert Hartshorn Link to comment
Andrew Posted October 6, 2020 Share Posted October 6, 2020 @Robert Hartshorn If you set a var in the Args/Vars, this will simply be set as an environment variable in any Run Script or Script Filter script. Link to comment
Robert Hartshorn Posted October 6, 2020 Author Share Posted October 6, 2020 @Andrew Thank you for the info! Is it possible to set the var in args/vars before I hit the script filter? (object flow: Args/Vars -> Script Filter -> Open File Action). From what I can tell the Script Filter needs to come first. But that could just be my infinite density at work Link to comment
deanishe Posted October 6, 2020 Share Posted October 6, 2020 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
Robert Hartshorn Posted October 7, 2020 Author Share Posted October 7, 2020 Thank you @deanishe. I ended up tethering a keyword to the arg util first and that worked perfectly. This is solved! Link to comment
giovanni Posted May 5, 2021 Share Posted May 5, 2021 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
Robert Hartshorn Posted May 5, 2021 Author Share Posted May 5, 2021 Hey @giovanni I hope I find you well. What is the primary reason that the user needs to populate the scope value via workflow variable? Can they just click the file filter itself and set the scope in the "Scope" tab? Link to comment
giovanni Posted May 5, 2021 Share Posted May 5, 2021 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. thanks!! Link to comment
deanishe Posted May 5, 2021 Share Posted May 5, 2021 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. giovanni 1 Link to comment
deanishe Posted May 5, 2021 Share Posted May 5, 2021 (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 May 5, 2021 by deanishe giovanni 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now