Cheng Posted October 30, 2016 Share Posted October 30, 2016 (edited) Newbie question here: I have created a script filter to convert a {query} to lower case and replace https with http: import sys query = "{query}" query = query.lower() if query.startswith('https://'): query = query.replace('https://', 'http://') sys.stdout.write('{"items":[{"title": "test", "args":"'+query+'"}]}') Then, I'd like to pass the processed {query} to an open url action. (See the attached image below) After I enter the keyword: ala a_url, and press enter, nothing happens. I can see the debug console printing out the correct JSON, but I am not sure how to pass the processed {query} to the "open url action", please help Edited October 30, 2016 by Cheng Link to comment
vitor Posted October 30, 2016 Share Posted October 30, 2016 A Script Filter is the wrong solution. You should have a Keyword connected to a Run Script connected to Open URL. Yes, that is more nodes, but will actually be simpler code and will be more efficient since it won’t run with every character press. When asking for help with your workflow please also post a link a to it. We’re not seeing the whole picture and the problem may be somewhere you’re not thinking of. Also give us your Alfred version. Link to comment
Andrew Posted October 30, 2016 Share Posted October 30, 2016 You'd be better off just using a keyword input to capture the query, then run it through a Run Script which does your processing. This simplifies things as you just output the URL from the script which will be used as the input of the Open URL. You could even do this without scripting using: Keyword input -> Replace util (replace http) -> Process util (lower case) -> Open URL. Cheers, Andrew Link to comment
Andrew Posted October 30, 2016 Share Posted October 30, 2016 @vitor you beat me to it Link to comment
Cheng Posted October 30, 2016 Author Share Posted October 30, 2016 22 minutes ago, Andrew said: You'd be better off just using a keyword input to capture the query, then run it through a Run Script which does your processing. This simplifies things as you just output the URL from the script which will be used as the input of the Open URL. You could even do this without scripting using: Keyword input -> Replace util (replace http) -> Process util (lower case) -> Open URL. Cheers, Andrew Really appreciate your help "Keyword input -> Replace util (replace http) -> Process util (lower case) -> Open URL" => this one is much easier. The "Process util" is called "Transform" in my alfred. Link to comment
Cheng Posted October 30, 2016 Author Share Posted October 30, 2016 23 minutes ago, vitor said: A Script Filter is the wrong solution. You should have a Keyword connected to a Run Script connected to Open URL. Yes, that is more nodes, but will actually be simpler code and will be more efficient since it won’t run with every character press. When asking for help with your workflow please also post a link a to it. We’re not seeing the whole picture and the problem may be somewhere you’re not thinking of. Also give us your Alfred version. Thanks Vitor! Link to comment
deanishe Posted October 31, 2016 Share Posted October 31, 2016 (edited) FWIW, simply replacing https with http is not super robust, as it's possible that https appears more than once in the URL, e.g.: https://web.archive.org/web/*/https://www.alfredapp.com/ Arguably better to use a Run Script with a slightly-modified version of your original code that only replaces https:// at the start of the URL: if query.startswith('https://'): query = 'http://' + query[8:] sys.stdout.write(query) Edited October 31, 2016 by deanishe Link to comment
vitor Posted October 31, 2016 Share Posted October 31, 2016 8 minutes ago, deanishe said: FWIW, simply replacing https with http is not super robust, as it's possible that https appears more than once in the URL, e.g.: https://web.archive.org/web/*/https://www.alfredapp.com/ Arguably better to use a Run Script with a slightly-modified version of your original code that only replaces https:// at the start of the URL That’s a fair point, but that case can also be covered by the Replace utility if we make it a regex substitution: deanishe 1 Link to comment
deanishe Posted October 31, 2016 Share Posted October 31, 2016 You're right. I always forget that Alfred's utilities support regexes. Link to comment
Cheng Posted November 1, 2016 Author Share Posted November 1, 2016 5 hours ago, deanishe said: FWIW, simply replacing https with http is not super robust, as it's possible that https appears more than once in the URL, e.g.: https://web.archive.org/web/*/https://www.alfredapp.com/ Arguably better to use a Run Script with a slightly-modified version of your original code that only replaces https:// at the start of the URL: if query.startswith('https://'): query = 'http://' + query[8:] sys.stdout.write(query) Cool, How can I hook up a script with a open url action? As I tried to use a script filter but being told that it is not what script filter is for. 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