Jump to content

Can't get multi-argument shell script to work


Recommended Posts

Hey all -

 

I'm trying to pass two arguments to a shell script in Alfred (I've tried both v2 and v1) and I can't seem to get any output.  The script works fine when run through the terminal, or when "silent" is unchecked in version 1, but there is no output to the Notification Center.

 

I've read the article here, and tried using read to parse the {query} string, but to no avail.  Here is the full script, fwiw:

read IP NETMASK <<< "{query}"
elinks -dump "http://jodies.de/ipcalc?host=${IP}&mask1=${NETMASK}&mask2=" | awk '/^Address:/,/^Hosts/'

Any ideas?

Link to comment

I was asking because it seems to be working for me, except if I turn that option on (naturally).

Try this, then. Instead of

read IP NETMASK <<< "{query}"

use something like

IP=$(cut -d " " -f1 <(echo "{query}"))
NETMASK=$(cut -d " " -f2 <(echo "{query}"))

Does it work for you?

Link to comment

Sure, here's a link to the exported workflow.

 

I don't have elinks and not sure what the output is supposed to be but could you try capturing the output that you are looking to get from the command in a variable and then echoing that? Also, in the notification center item, set your title and set the text to {query} to grab the text from the previous piece

Link to comment

Also, in the notification center item, set your title and set the text to {query} to grab the text from the previous piece

That’s what I was thinking could be the problem, when asking to see the workflow. If the script itself is working well, making that small adjustment should make the workflow work.

Link to comment

Thanks for the suggestions.  I've changed the script to look like this:

IP=$(cut -d " " -f1 <(echo "{query}"))
NETMASK=$(cut -d " " -f2 <(echo "{query}"))
RETURN=$(elinks -dump "http://jodies.de/ipcalc?host=${IP}&mask1=${NETMASK}&mask2=" | awk '/^Address:/,/^Hosts/')
echo ${RETURN}

but nothing has changed.  I've also added {query} to both the "Title" and "Text" sections of the Post Notification action, but still nothing.

Link to comment

Aha, got it!  Apparently elinks wasn't in Alfred's PATH variable.  I just added the full path to the elinks executable and it works now.

 

It looks like Alfred doesn't read my .bash_login file, probably because it's not a login shell :)  Anyway, I can poke around and put the PATH variables elsewhere.

 

Thanks for helping lead me to the solution!

Link to comment

It looks like Alfred doesn't read my .bash_login file

 

Completely forgot about that. Yes, it’s a common issue, as Alfred does not read those files. A common solution would be to just add to the top of the script

source "${HOME}/.bash_login"

or

PATH="/usr/local/bin:$PATH"

(or whatever you need your PATH to be).

 

That way you can keep the rest of your script pretty much intact, without having to always remember to use the full path of the executables.

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