IAmDamoSuzuki
IAmDamoSuzuki

Reputation: 33

Using double quotes in Applescript command Do Shell Script Echo

I'm trying to use applescript to run a command line process. A simplified version of the Applescript looks like this

do shell script "echo bwfmetaedit --INAM=\"name\" --IART=\"artist\" --ICRD=\"date\" /desktop/filepath.wav"

with the expected result being

bwfmetaedit --INAM="name" --IART="artist" --ICRD="date" /desktop/filepath.wav

If I were to just to run that command in Terminal, I get the correct output. However with applescript I get the following result. Note the missing double quotes around the values.

"bwfmetaedit --INAM=name --IART=artist --ICRD=date /desktop/filepath.wav"

What am I missing here? I need the double quotes around the values or else the command wont run properly.

Thanks, Morgan

Upvotes: 3

Views: 6881

Answers (4)

Dhamu
Dhamu

Reputation: 11

To call this inside code, try this

set myStr to "/bin/echo Hello here is \\\"Quoted String\\\"

The do script call will write it with double quote(s).

do script myStr in front window

Upvotes: 0

Laser Hawk
Laser Hawk

Reputation: 2028

For me my challenge was

osascript -e 'tell application "Simulator" to quit'

So my solution was

do shell script osascript -e 'tell application \"Simulator\" to quit'"

You have to escape before the first double-quote and then again before it. Thanks for tips everyone!

Upvotes: 0

adayzdone
adayzdone

Reputation: 11238

Try:

do shell script "echo bwfmetaedit --INAM=\\\"name\\\" --IART=\\\"artist\\\" --ICRD=\\\"date\\\" /desktop/filepath.wav"

Upvotes: 3

andrewdotn
andrewdotn

Reputation: 34813

The quotes are being passed properly, it’s just that the shell doesn’t echo them because they are part of the shell syntax.

If you try this AppleScript that prints each argument on its own line:

do shell script "sh -c 'for F in \"${@}\"; do echo \"${F}\"; done' \"${0}\" echo bwfmetaedit --INAM=\"name with spaces\" --IART=\"artist with spaces\" --ICRD=\"date with spaces\" /desktop/filepath.wav"

Then you will see that the output is:

"echo
bwfmetaedit
--INAM=name with spaces
--IART=artist with spaces
--ICRD=date with spaces
/desktop/filepath.wav"

Each argument passed to echo is parsed properly as if it were quoted. The quotation marks are at the beginning and end because it is an AppleScript string with embedded newlines.

Upvotes: 1

Related Questions