Jump to content

How to Deal with Arguments in Bash Workflow


Recommended Posts

So I have a bash script below, that I run that allows me to pass in 2 - 3 arguments that will then download a dummy image from lorempixel.com.  

 

#!/bin/bash

if [ $3 ]
	then
		wget http://lorempixel.com/$1/$2/$3'>http://lorempixel.com/$1/$2/$3 -O $1x$2-$3.jpg
	else
		wget http://lorempixel.com/$1/$2/ -O $1x$2.jpg
fi

 

 

I want to set this up as a workflow, but not sure how to deal with the {query} part in the script.  Right now I have a keyword that links to the "Run Script" action that breaks when it gets there.  I realize I can probably tweak this script so that the query matches the output path, but I want to keep it readable.

 

Please help?!

Link to comment

Additionally, I'd like to be able to feed this back into Alfred so it that its asks where to download this image to, so that I can have it put in any project I'm working on.  I assume there is a way to do this, by having it download to a tmp directory and then moving the path to whatever the new {query} would be, iI just need some help walking through it.  

Link to comment

To answer your first question, {query} will be replaced by the content typed in alfred. If you want it to be several arguments, you'll have to find a way to parse it (with spaces, comas, or whatever suits you).

 

As for your second question, I don't understand what it is that you want to feed back into alfred.

Link to comment

In Alfred, create a run script action, and be sure to uncheck "escape spaces".  Then use this to get {query} into arguments you can use.

 

#!/bin/bash

read a1 a2 a3 <<< "{query}"

if [ $a3 ]
	then
		wget http://lorempixel.com/$a1/$a2/$a3'>http://lorempixel.com/$a1/$a2/$a3 -O $a1x$a2-$a3.jpg
	else
		wget http://lorempixel.com/$a1/$a2/ -O $a1x$a2.jpg
fi

 

 

I'm not sure how you'd then get Alfred to prompt you for where to save it.

Link to comment
  • 9 years later...
On 3/18/2013 at 4:56 AM, phallstrom said:

In Alfred, create a run script action, and be sure to uncheck "escape spaces".  Then use this to get {query} into arguments you can use.

 

#!/bin/bash

read a1 a2 a3 <<< "{query}"

if [ $a3 ]
	then
		wget http://lorempixel.com/$a1/$a2/$a3'>http://lorempixel.com/$a1/$a2/$a3 -O $a1x$a2-$a3.jpg
	else
		wget http://lorempixel.com/$a1/$a2/ -O $a1x$a2.jpg
fi

 

 

I'm not sure how you'd then get Alfred to prompt you for where to save it.

 

@phaistonian how would you pass that a1, a2, etc up to another action say Open URL action?

Link to comment
1 hour ago, vitor said:

@Lexyz echo -n "Whatever text you want to pass along"


@vitor Right i c

Also wonder how would you access the actual keyword in bash?

`$X` gives you a params, but what I really need is a real keyword 👇


image.png.77034445776bcf4f79bff91fecb9ee5e.png

Edited by Lexyz
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...