ShellEx / Shell after going 4.7

Hi,

first surprise after going from GP 4.5.8 to GP 4.7

In my Global Rack Script I make use of Shell() or ShellEx() to invoke AppleScript, e.g. to run a BGM playlist in music, bring an app to front of the screen, skip to the next track in Music etc.

This was OK in 4.5.8, however in 4.7 only part of it is working:

retVal := ShellEx(“osascript ‘/Users/alexander/Documents/Gig Performer/AppleScript/Playlist-BGM1.scpt’”)

Is OK, the script executes and starts Music with a playlist specified in the .scpt file

retVal := Shell(“osascript -e ‘tell Application \"Music\" to play (next track)’”)

Is not working anymore - I get the the returncode 256, which I could not interpret so far.

What do I oversee?
BBB

That stuff hasn’t changed since 4.5

Why are you using Shell instead of ShellEx the second time? ShellEx works quite differently than Shell

1 Like

Good question, I also tried ShellEx(), however I got nothing as a return value… Same result. The AppleScripts are working, command line scripts are not :frowning:
Same result on both of my macs…

Here’s a small gig to demonstrate

ShellEx.gig (51.4 KB)

Just createan AppleScript from the txt file in your GP folder, adjust the path in the Global Rack Script, create a playlist named "BGM " and check

Playlist-BGM1.txt (311 Bytes)

The Green Button ist working, the two others not :frowning:

You can confirm that this is running with 4.5.8?

I don’t have installed 4.5.8 anymore, but yes, these Shell(“osascript -e ‘…’”) have definitly been running on GP 4.5.8 :face_with_raised_eyebrow:

I think this gots something to do with correct escaping the " in my osascript command string :thinking:

I made some additions: the ESC character '' gets added to the command string, therefore osascripts drops an error message (unfortunately in German on my system

You can see in the Print output, that the backslash got added!

So question: how do I do correct escaping in these strings?

OK, just a simple test

Print an embedded double quote like described in the GPscript manual:

“This is a string containing an embedded \” double-quote"

You will get the backslash…

Sorry, smells like a bug :frowning:

Workaround for today

i.e. strip the backslashes from the temp command line :crazy_face:

Now, it’s working…

Actually a better workaround is probably this

const
   q : String = <<<">>> // "

(The comment and quote at the end fix the otherwise broken syntax highlighting caused by a single quote)

Now you can just write things like

   q + "foo"  + q

which would actually result in a string that looks like this

“foo”

2 Likes

Actually that was silly suggestion for this particular purpose. Just put the whole thing inside a heredoc


Shell(<<<osascript -e ‘tell Application "Music" to play (next track)’)>>>)

3 Likes

Cool! I was not aware of <<<. >>> :blush: