Page 1 of 1

Embedded Script Not Working

PostPosted: Mon Mar 26, 2012 12:17 am
by IDontDoWindows
Code: Select all
shell is /bin/bash

textFileName=basename "$1"
/usr/local/bin/mtcmail -t me@me.com -b me@me.com -s "$textFileName - la de dah"


Not working. Sends the email, but does not include the file name. I've attempted various versions of this, and none of them work.

Re: Embedded Script Not Working

PostPosted: Mon Mar 26, 2012 2:06 pm
by Mr_Noodle
In general, it's a good idea to test scripts outside of Hazel first.

In this case, the first line is incorrect. You are just setting the variable textFileName to the string basename...

If you want basename to be executed and the output applied to the variable, you need to do:

Code: Select all
textFileName=`basename "$1"`


Note that those are backticks, not single quotes. If you are typing on a US keyboard, it's the key in the upper left.

Re: Embedded Script Not Working

PostPosted: Mon Mar 26, 2012 5:42 pm
by sjk
Mr_Noodle wrote:Note that those are backticks, not single quotes.

Alternatively, use $(…) instead of backticks for command substitution, i.e.:

Code: Select all
textFileName=$(basename "$1")

Re: Embedded Script Not Working

PostPosted: Tue Mar 27, 2012 2:36 pm
by IDontDoWindows
Thanks. That was driving me nuts.

Now if I could remember what I was working on when I was trying to do that...