Page 1 of 1

sending notifications with iMessage via osascript

Posted: May 29th, 2012, 4:22 pm
by Chanch
I am trying to send imessage notifications from a Sab post-processing script. I've tried a few things so far:
This script works from the command line

Code: Select all

#!/bin/bash
#sends message via Messages to BUDDY
#[email protected]
osascript -e 'on run argv' -e 'tell application "iChat"' -e 'set theMessage to argv' -e 'send theMessage to buddy "[email protected]" of service 1' -e 'end tell' -e 'end run' "$*"
then I changed it a little for Sab, but if "$3" ,the clean file name, has spaces in the name it only sent the 1st item. (I assumed that was because of the "item 1 of argv" in the applescript part)

Code: Select all

#!/bin/bash
#sends message via Messages to BUDDY
#[email protected]
osascript -e 'on run argv' -e 'tell application "iChat"' -e 'set theMessage to item 1 of argv' -e 'send theMessage to buddy "[email protected]" of service 1' -e 'end tell' -e 'end run' "Your Show has finished downloading "$3""
so I tried taking out the "item 1 of argv" , but now I get this error in sab
60:119: execution error: iChat got an error: Can’t make {"Your Show has finished downloading Too", "Big", "To", "Fail", "2011", "DVDRip", "XviD", "BeStDivX"} into type text, file, constant. (-1700)
any ideas? Thanks

Re: sending notifications with iMessage via osascript

Posted: May 29th, 2012, 4:44 pm
by sander
Change "$3" into \"$3\" ?
Play with IFS?
Put $3 only after the -e ?
Google "bash spaces in variables"?

I have no osascript so I can't test it for you.

I hate bash because of these problems. I would put it in python script ... problem solved.

Re: sending notifications with iMessage via osascript

Posted: May 29th, 2012, 6:00 pm
by Chanch
Thanks Sander, I just got to work. I'll try your suggestions when I get home. Escaping the quotes seems like it might work to me. Youre right Ive been slacking on learning python though. I need to set some time aside for that

Re: sending notifications with iMessage via osascript

Posted: May 30th, 2012, 3:59 pm
by Chanch
This works:

Code: Select all

osascript -e 'on run argv' -e 'tell application "iChat"' -e 'set theMessage to item 1 of argv' -e 'send theMessage to buddy "[email protected]" of service 1' -e 'end tell' -e 'end run' "Your Show has finished downloading: ""$3"
I double quoted the message "Your Show has finished downloading: " and the "$3" separately.