2

Here's a command that works fine when I paste it into the Mac Terminal window:

echo -n -e \\033]0\;My Custom Window Title Here\\007 ; ping www.google.com

In particular, it sets the Terminal's title to include the string "My Custom Window Title Here", then starts pinging www.google.com.

Now what I want to do is have the above command run in a separate Terminal window instead, so I enter this:

osascript -e 'tell app "Terminal" to do shell script "echo -n -e \\033]0\;My Custom Window Title Here\\007 ; ping www.google.com"'

… but all I get is this error:

dyld: DYLD_ environment variables being ignored because main executable
(/usr/bin/osascript) is code signed with entitlements 59:60: syntax error: Expected “"” but found unknown token. (-2741)

If I get rid of the backslashes, osascript will run the command, but then of course the custom window title doesn't get set.

Is there some way I can get my bash command through osascript's parser intact, so that I can have my ping command execute in its own window AND with a customized window title?

  • Expected “"” but found unknown token... – Ruskes Mar 31 '14 at 23:20
4

Because it's going through another layer of interpretation, you need to escape the escapes -- essentially, you need to double the backslashes:

osascript -e 'tell app "Terminal" to do script "echo -n -e \\\\033]0\\;My Custom Window Title Here\\\\007 ; ping www.google.com"'
  • do shell script is not a Terminal command. Use "do script" instead. – adayzdone Apr 1 '14 at 4:13
  • @adayzdone: good point. "do shell script" is a built-in AppleScript command, which can be executed by Terminal and sort-or-works... but not quite. I've edited the code snippet. – Gordon Davisson Apr 1 '14 at 5:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .