rrosson Posted April 19, 2013 Share Posted April 19, 2013 I am attempting to write my first workflow to assist me with doing a task that I have to perform on a regular basis. The base of this workflow will be to lookup data from a website with a give argument and query, For each argument (type) selects a given URL to apply the query. With it all put together it should open the resulting URL with the information I am looking for. I have written a quick and dirty bash script that takes 2 arguments that works but I would rather do this in alfred's workflow to avoid having to run a terminal command to open a browser window. Below is a sanitized version of my bash script. #!/bin/bash # $1 will be what we are looking for # $2 will be what we input as an argument MYNAME=`basename $0` if [ $# -eq 0 ]; then echo "Usage: $MYNAME type query" 1>&2 exit 2 fi case "$1" in abc) open http://www.myurl.com/blah.aspx?q=$2&v=abc ;; def) open http://www.myurl.com/blah.aspx?q=$2&v=def ;; ghi) open http://www.myurl.com/blah.aspx?ghi=$2 ;; jkl) open http://www.myurl.com/blah.aspx?q=$2&v=jkl ;; mno) open http://www.myurl.com/blah.aspx?mno=$2 ;; pqr) open http://www.myurl.com/blah.aspx?$2 ;; stu) open http://www.myurl.com/blah.aspx?q=$2&v=stu ;; *) echo "oops" ;; esac any guidance or samples showing how to do this would be awesome TIA Link to comment
rice.shawn Posted April 19, 2013 Share Posted April 19, 2013 Basically the same question is asked here: http://www.alfredforum.com/topic/2041-can-we-use-2-arguments/ The simplest way is to create a script that parses the argument and then feeds it to the next script. Link to comment
jdfwarrior Posted April 20, 2013 Share Posted April 20, 2013 Basically the same question is asked here: http://www.alfredforum.com/topic/2041-can-we-use-2-arguments/ The simplest way is to create a script that parses the argument and then feeds it to the next script. Thanks Shawn Link to comment
rrosson Posted April 22, 2013 Author Share Posted April 22, 2013 If I am reading this correctly I will have one main script and a script for each based on the first argument. Is there a workflow that is already working that takes 2 arguments that I can look at to possibly see how it is being done? TIA Link to comment
rice.shawn Posted April 22, 2013 Share Posted April 22, 2013 You could do it that way, or you could just have it as the beginning of the script. Here's a php version: $var = explode(" ","{query}"); $output = ""; foreach( $var as $key => $val ) : $output .= "Arg #" . $key . ": " . $val . "\r\n"; endforeach; echo $output; So, with this, I just turn the query into an array via the explode function, using a space as the delimiter (make sure you don't escape spaces), and then I have them as an array. You can do something similar in bash. 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