osascript ignores escaped quotes

I need to pass osascript this string as an argument after -e

The equalizer preset used for the demo purpose is mine. I store the preset’s name in a shell variable Preset. I’m able to assemble this string in the command line. The solution I came up with is as follows:

However, it chokes as soon as I add osascript as in

I ran this shell script as do shell script in ScriptEditor, and no matter how I bend it it compiles as

which, of course, fires up the endless torrent of complains that “this token can’t go after that identifier”. I tried to turn on -o and -t switches to xargs to start it in interactive mode and “echo” the command to stderr before it being executed (all according to the xargs manual) but stumbled into the same wall: incorrect syntax related to an out-of-place identifier.

What do I do wrong? How to pipe to osascript a string with single and double quotes preserved in the command line as the result of the previous command?
(To test, put the name of any preset between the quotes in the variable Preset).

Model: MacBook Pro
AppleScript: 2.3.2
Browser: Safari 537.86.7
Operating System: macOS 10.9

Hi.

It can get pretty hairy when you’re dealing with quotes within quotes within quotes. :slight_smile:

I haven’t tested this with iTunes, but an equivalent test script for the Finder works OK in Mojave:

do shell script "Preset=\"Bestial devastation +10\" ; echo 'tell application \"iTunes\" to set current EQ preset to  \"'$Preset'\"' | xargs -0 -I % osascript -e %"

Hi,
Thank you, but I need to run in the command line, and there your code errors out to

As soon as single quoted the variable expansion falters.

Model: MacBook Pro
AppleScript: 2.3.2
Browser: Safari 537.86.7
Operating System: macOS 10.9

Solved.

For some reason this version worked

A strange thing is that although osascript requires single-quoting arguments to its multiline mode option -e when supplied as standard input, the line above is comfortable with unquoted argument which is a revelation for me.

Model: MacBook Pro
AppleScript: 2.3.2
Browser: Safari 537.86.7
Operating System: macOS 10.9