Jump to content

[HOW TO] Pass results from script to Alfred, then run another script and return it's value to Alfred as well

Recommended Posts

Hi, I am working on a workflow that will allow to search for anime movies, then if pressed enter instead of list of anime we'll get list of episodes for that certain anime.




here after I write "naruto" and hit enter, I would like to see something like this below.




Instead, after hitting enter Alfred closes window (what is expected behaviour).



Right now, I put all the logic into python script that checks if there is only one anime with a given name, then it should show list of episodes instead of list of available anime movies.

it seems to be working fine, but minus is that I need to parse a lot of arguments in one script. Instead I would prefer to have a graph with all the possibilities. 


I am using Script Filter with additional "{query}" parameter to achieve that.

It's my first workflow, then I can miss something obvious.



Any ideas?

Link to comment

Hi @giovanni, thank you very much for your answer. It's really helpful, although I guess it does not completely solve my issue.

I may use AppleScript or TextMarkers. The first one is pretty time consuming and actually pretty stinky solution. The second one sends all the logic to the Python script, where I would need to parse arguments and depending on multiple arguments decide what to do. Instead, I would imagine tool like Alfred would allow us to create a graph of Script Filters that we just need to specify what query parameter to pass. I bet it does somehow! 


Before I go with Text Markers, do you have any other ideas?

Link to comment

I am not sure I follow the whole logic (i.e. are you querying a single table or 2?), but if you want two distinct outputs, you need two inputs. you can either split your python script and have each script filter call one python script, or (better I think) call it twice with different arguments... or, if your initial list is fixed, you can use a list filter... if you can describe the logic in a bit more detail I am sure somebody on here will be able to help. 

Link to comment
22 hours ago, kornel45 said:

I would imagine tool like Alfred would allow us to create a graph of Script Filters that we just need to specify what query parameter to pass.


It does work like that when you connect a second Script Filter to the first one. The arg field of each item in the JSON feedback is what’s passed to the next Script Filter (or any element) when that item is actioned.


You need to connect two Script Filters together: the first one searches for the show and passes the show's ID (or title or whatever the API wants) to the second Script Filter, which lists the episodes.


You can either write two Python scripts or make your single script a command-line program that works like:


script.py <query>

script.py --episodes <title>

Then you set the second Script Filter to use Language = /bin/zsh and put /usr/bin/python3 script.py --episodes "$1" in the Script box.



If you really want to have only one Script Filter so you can easily start a new search, then you will need to do some query parsing. The best way to do that is usually to use a delimiter in the query. If you set valid to false on each item, Alfred expands the search query to the value of arg and calls the same Script Filter again, instead of passing control to the next workflow element.


Here's a Python workflow I wrote that works that way. Here's a demo of another workflow that works the same way:






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