Correct UDP syntax in "do shell script"?

347 views
Skip to first unread message

MattM

unread,
Feb 7, 2018, 9:29:50 AM2/7/18
to QLab
I'm having a heck of a time sending OSC commands through Applescript.  

I have one workspace open, with a cue whose cue number is "time1Pl" (no quotes).

I can get standard OSC commands that don't involve quotes to go through fine, like:

do shell script "echo /cue/selected/start >/dev/udp/localhost/53535"


But suppose I'm trying to address the time1Pl cue, and change its live text value to "4.0000".  If I send the following command as an OSC Message network cue in QLab, it works:


/cue/time1Pl/text "4.0000"


Trying to send the same command via do shell script in Applescript, I believe, should look like this:


do shell script "echo /cue/time1Pl/livetext \\\"4.0000\\\" >/dev/udp/localhost/53535"


This command doesn't work.  I'm assuming it has something to do with escaping the quotes around 4.0000.  I've seen a couple different ways online of what's supposedly necessary to escape quotes in a shell script, but maybe I don't have it right.  


Any ideas?


TIA,

M2




Chris Ashworth

unread,
Feb 7, 2018, 10:52:26 AM2/7/18
to ql...@googlegroups.com
Hi Matt,

Try this:

do shell script "echo \"/cue/time1Pl/liveText \\\”4.0000\\\"\" > /dev/udp/localhost/53535"

micpool

unread,
Feb 7, 2018, 10:58:38 AM2/7/18
to QLab
First off liveText has a capital T

a single backslash will escape a quote.

You can get a much more readable (and easily adaptable ) script if you use this form:

tell application id "com.figure53.QLab.4" to tell front workspace

set oscCmd to "/cue/time1Pl/liveText \"4.00\""

do shell script "echo " & the quoted form of (oscCmd) & " | nc -u -w 0 127.0.0.1 53535"

end tell


Mic


On Wednesday, February 7, 2018 at 2:29:50 PM UTC, MattM wrote:
I'm having a heck of a time sending OSC commands through Applescript.  

Trying to send the same command via do shell script in Applescript, I believe, should look like this:

MattM

unread,
Feb 7, 2018, 11:35:58 AM2/7/18
to QLab
Foiled by a capital T!

OK, so revisiting my original do shell script command: replacing "livetext" with "liveText", this command works:

do shell script "echo /cue/time1Pl/liveText \\\"4.0000\\\" >/dev/udp/localhost/53535"



But Mic, to your comment about escape characters, using my original syntax, this does not work:

do shell script "echo /cue/time1Pl/liveText \"4.0000\" >/dev/udp/localhost/53535"


I had read somewhere else before my original post (here: https://stackoverflow.com/questions/14737414/using-double-quotes-in-applescript-command-do-shell-script-echo) that the extra slashes were necessary because of how the shell parses the command.  That link doesn't explain why very well, but it gave me the idea to try that.


Mic, as to your other suggestion -- to split the specific OSC command out into its own variable -- that's very useful and I will likely use that.  It would let me avoid a lot of this foolishness with the quotes & split off the actual sending of the UDP command to a handler.

Rich Walsh

unread,
Feb 7, 2018, 12:52:44 PM2/7/18
to ql...@googlegroups.com
You need to look really carefully at the subtle differences. Note that Mic’s suggestion includes “the quoted form of”, ie:

do shell script "echo '/cue/time1Pl/liveText \"4.00\"' | nc -u -w 0 127.0.0.1 53535"

Inside the ' ' quotes, the " only need to be escaped once with \ so that AppleScript treats them as " inside the string, not " to indicate the end of a string.

Your version does not have the ' ' quotes for echo so that echo knows what it is echoing: echo needs to see a local escape of the " with a \, so AS needs to see \\ and \", ie: \\\" for echo to see \" – right?

Try it directly in the Terminal to see what I mean:

Mic’s version: echo '/cue/1/liveText "4.0000"' returns /cue/1/liveText "4.0000"

Your version: echo /cue/1/liveText \"4.0000\", also returns /cue/1/liveText "4.0000"

To achieve your version, AS needs to escape both the \ and the ", so \\\".

I wish I could explain that clearly! Basically, put the thing you are echoing inside ' '…

Rich

micpool

unread,
Feb 7, 2018, 12:59:00 PM2/7/18
to QLab
On Wednesday, February 7, 2018 at 4:35:58 PM UTC, MattM wrote:
 to your comment about escape characters, using my original syntax, this does not work:

do shell script "echo /cue/time1Pl/liveText \"4.0000\" >/dev/udp/localhost/53535"



Sorry I wan't clear. In Applescript  you can create  double quotes within a string  by preceding them with a single backslash, as in my example.

To do the same thing in the shell script you also have to esc the backslash itself so you end up with \\\"   which can get messy quite quickly.

If your interested in the netcat  command and options at the end of the shell script..... 


Mic
Reply all
Reply to author
Forward
0 new messages