Jump to content

Workflow with 2 arguments


Recommended Posts

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

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

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

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