jarrah Posted March 14, 2014 Share Posted March 14, 2014 (edited) Hello, I'm on the verge of purchasing the PowerPack because I'm hoping the following is possible, and if it is possible I'll buy it, but I just need help implementing it please. I would like to feed the following query into Alfred to launch a URL to a website: "subscribe 123456789 Reminder phrase with multiple spaces" The first two will always be in the same format, with subscribe being the keyword and the number being the reference. The text after the number will vary and will have multiple spaces, but needs to be treated as the second query that can be any size (though not more than 255 chars). Keyword - "subscribe" Query1 - "<an ID with no spaces>" Query2 - "A text phrase with multiple spaces" The URL that needs to be generated looks like this: https://domain.com/subscription/sub?s&what=data&id={query1}¬e={query2} e.g. https://domain.com/subscription/sub?s&what=data&id=123456789¬e=Reminder%20phrase%20with%20multiple%20spaces I'm no good at scripting so I'm hoping someone wouldn't mind helping out with this if possible please? Thanks! Edited March 14, 2014 by jarrah Link to comment
Andrew Posted March 14, 2014 Share Posted March 14, 2014 Hello, I'm on the verge of purchasing the PowerPack because I'm hoping the following is possible, and if it is possible I'll buy it, but I just need help implementing it please. I'm no good at scripting so I'm hoping someone wouldn't mind helping out with this if possible please? Thanks! This is entirely possible with the Powerpack - you can split arguments any way you like and formulate URLs. I actually have a few nice examples of doing just this, so let me know if you buy the Powerpack and I'll share them with you Cheers, Andrew Link to comment
vitor Posted March 15, 2014 Share Posted March 15, 2014 That should actually be pretty straightforward — just a few lines in bash. The community in the forums is also very helpful, so if you end up getting the powerpack, we can help you build the workflow. Link to comment
jarrah Posted March 16, 2014 Author Share Posted March 16, 2014 Sounds great, thank you Andrew and Vitor! PowerPack is now purchased and I'm very appreciative and looking forward to your help. This should save me around 10 clicks and 3 lots of extra text entry so can't wait! Link to comment
Andrew Posted March 16, 2014 Share Posted March 16, 2014 Sounds great, thank you Andrew and Vitor! PowerPack is now purchased and I'm very appreciative and looking forward to your help. This should save me around 10 clicks and 3 lots of extra text entry so can't wait! Thanks for buying! There are plenty of ways of splitting args, and this is dependent on the script language you use. Here is a nice simple example workflow of splitting arguments and opening a url using bash: https://dl.dropboxusercontent.com/u/6749767/Alfred/Workflows/Kitten%20Image.alfredworkflow Let me know if you need any help modifying this for your purpose Cheers, Andrew Link to comment
jarrah Posted March 17, 2014 Author Share Posted March 17, 2014 (edited) Thanks for pointing me in the right direction Andrew. After a bit of Google'ing I found the following solution works for me: #!/bin/bash alfin="{query}" idnum=`echo $alfin | awk '{print $1}'` descrip=$(echo $alfin | cut -d " " -f2-) open "https://domain.com/subscription/sub?s&what=data&id=$idnum¬e=$descrip" Edited March 17, 2014 by jarrah Link to comment
vitor Posted March 17, 2014 Share Posted March 17, 2014 (edited) You’re mixing a lot of different syntaxes and commands, using different approaches to do the same thing. You also have unnecessary elements for it to work as a workflow. It should work as you have it now, but if you want to make it cleaner and more maintainable, I suggest something like (without changing yours too much) alfin="{query}" idnum=$(echo "${alfin}" | cut -d ' ' -f1) descrip=$(echo "${alfin}" | cut -d ' ' -f2-) open "https://domain.com/subscription/sub?s&what=data&id=$idnum¬e=$descrip" You might also have some trouble in the future, if your phrase ever uses a character that needs to be url encoded. For that to work, change the line descrip=$(echo "${alfin}" | cut -d ' ' -f2-) to descrip=$(echo "${alfin}" | cut -d ' ' -f2- | perl -MURI::Escape -wlne 'print uri_escape ($_)'). That last bit will take your characters and encode them so they can be used as part of a url. Edited March 17, 2014 by Vítor Link to comment
jarrah Posted April 23, 2014 Author Share Posted April 23, 2014 Thanks Vitor! I lost track of this thread so apologies for the late response, and thanks for the improved descrip code! Link to comment
jarrah Posted April 23, 2014 Author Share Posted April 23, 2014 I've been looking into how Alfred can open custom Web Searches in a specific browser and found a useful post that said to use the Workflow template "Open custom URL in specified browser", and this works great. However, how do I do the same for the script in this post? The "open" command is tied to the script because of the variables, so not sure how I can pass that to another object that says open Chrome for example. Thanks. Link to comment
jdfwarrior Posted April 23, 2014 Share Posted April 23, 2014 I've been looking into how Alfred can open custom Web Searches in a specific browser and found a useful post that said to use the Workflow template "Open custom URL in specified browser", and this works great. However, how do I do the same for the script in this post? The "open" command is tied to the script because of the variables, so not sure how I can pass that to another object that says open Chrome for example. Thanks. You can specify an app with the open command. By just telling it to open a URL it will open it with the default web browser. You could however do something like this... open -a /Applications/Google\ Chrome.app http://yahoo.com to open a url in Chrome. Link to comment
jarrah Posted April 23, 2014 Author Share Posted April 23, 2014 Works like a charm, thanks very much! Link to comment
Marcin Bogdanowicz Posted November 4, 2014 Share Posted November 4, 2014 Thanks for this topic. I've got an additional question: how to remove diacritic marks in queries using commands of this bash script? I've been messing with commands such as sed and tr, but to no avail. Apart from this, some may find useful my tweaking with the script: I've discovered that for this script to work, the option of 'escape spaces' has to be unchecked. Link to comment
Marcin Bogdanowicz Posted November 7, 2014 Share Posted November 7, 2014 Does no one know an answer? At least tell me how to add to this script a snippet with a php code? In php, which I know a bit, I believe this getting rid of diacritics may be easier achieved. By the way, I've tried yet another bash method, which I googled fortunately, namely that of iconv command, but again to no avail: e.g. following that: http://stackoverflow.com/questions/1975057/bash-convert-non-ascii-characters-to-ascii Link to comment
heyJoeCampbell Posted June 14, 2018 Share Posted June 14, 2018 Hi @jarrah please provide the workflow — I am looking to accomplish the same thing. 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