andy4222 Posted August 13, 2021 Posted August 13, 2021 (edited) Hi Everyone, I'm trying to modify the Searchio workflow a bit to suit my needs and facing some issue where I have to press enter trigger the script filter What I want: - When I enter "yts" without args and press enter, it opens YouTube. When i enter "yts" and provide an arg, it should start search via searchio's script and display results. With my changes, the 1st part works great with a conditional, but when I provide an arg after "yts" I have to press a second enter to display results. Is there way I can make it work without having to press enter to show results? (I tried inducing a fake enter via a script in between the keyword and script filter, but that didn't work either) Later, I realized that I'd need to trigger the script filter directly with a keyword, but with that, it kept opening youtube from the script filter: ``` if [ -z $1 ] then open "youtube" else ./search youtube-us "$1" fi ``` Of course, since the arg is always null as soon as i enter the keyword. Can anyone please help with this? Modifed workflow: https://www.dropbox.com/s/1abqmspjfd3zobr/Searchio!.alfredworkflow?dl=0 Edited August 13, 2021 by andy4222
deanishe Posted August 13, 2021 Posted August 13, 2021 18 minutes ago, andy4222 said: Is there way I can make it work without having to press enter to show results? No. At least not like that. If your Script Filter doesn't require an argument, Alfred will always run it at least once with no argument. What you want is for the search Script Filters to have "Argument Optional" set and to show an "Open this website in your browser" item if there's no query, but you've picked a workflow that makes that really hard to change.
andy4222 Posted August 13, 2021 Author Posted August 13, 2021 1 hour ago, deanishe said: "Open this website in your browser" item if there's no query The code I pasted above was part of the script filter and tries to kinda do that, but it doesn't wait for me to press enter and opens the URL as soon as the keyword is triggered. Any way to induce the enter?
deanishe Posted August 13, 2021 Posted August 13, 2021 2 minutes ago, andy4222 said: but it doesn't wait for me to press enter and opens the URL as soon as the keyword is triggered. Well, no. The entire point of Script Filters is that they’re run before you press ↩. They exist solely to generate the list of things you can press ↩ on. A Script Filter is supposed to output a list of results for Alfred to show the user, but you're calling a browser instead. Assuming you've set "Argument Optional" on the Script Filter, your script should look something like this: if [ -z "$1" ]; then echo '{"items": [{"title":"Open YouTube.com", "arg": "https://www.youtube.com"}]}' exit 0 fi ./search youtube-us "$1" That will work, but modifying Searchio! that way is a bad idea because it will overwrite your changes the next time you add or remove a new search. andy4222 1
andy4222 Posted August 13, 2021 Author Posted August 13, 2021 This definitely solves my problem. I'll keep that in mind when I add/remove searches, which I don't expect I'll do anytime soon. Appreciate your help on this @deanishe. Thanks for creating this amazing app!!
deanishe Posted August 14, 2021 Posted August 14, 2021 4 hours ago, andy4222 said: Thanks for creating this amazing app I only made the workflow. Andrew is Alfred's developer. andy4222 1
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