Jump to content
apermanentwreck

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?!

Share this post


Link to post

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.  

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...