0
#/bin/bash
corr="apple"
echo $corr

osascript -e 'tell application "Messages" to send  "Did you mean "'"$corr"'" "  to buddy  "A"'

Error:

51:57: syntax error: A identifier can’t go after this “"”. (-2740)

If I just pass

osascript -e 'tell application "Messages" to send  "Did you mean $corr "  to buddy  "A"'

the message comes like "Did you mean $corr"

I have tried everything mentioned at Pass in variable from shell script to applescript

2
  • formatting was horrendous. should be more readable now Commented May 22, 2015 at 15:45
  • If you are trying to send the literal string Did you mean "apple", then you aren't escaping the quotation marks around apple. The first one closes the message, so that apple is an unexpected identifier, not part of the message string. Commented May 22, 2015 at 15:58

1 Answer 1

1

There is a very good explanation with decent examples at the very end of here.

Based on that, I was able to make this work (using TextEdit, not Messages):

 #!/bin/sh
rightNow=$(date +"%m_%d%B%Y")
osascript -e 'on run {rightNow}' -e 'tell application "TextEdit" to make new document with properties{name: "Date003.txt", text:rightNow}'  -e 'end run' $rightNow

I also found that I had to be VERY careful about the single and double quotes. For some reason, my keyboard kept replacing the plain quotes with curled quotes. Annoying.

Sign up to request clarification or add additional context in comments.

3 Comments

One can disable that option (replacing quotes) in TextEdit's preferences
@Zero Thank you! I rarely use TextEdit for shell scripts, but I thought this would be simple. Now it is fixed.
While not essential in this particular example, I would also strongly recommend double-quoting $rightNow at the end. It's a very good habit to get into when writing bash scripts as it ensures correct behavior should the string being inserted contain any spaces. (Bash is such a POS it can't even do variable substitution right - instead it just inserts the raw string as-is and parses it as code. e.g. If the string is foo bar then $rightNow will be replaced by two separate arguments, foo and bar, unless you explicitly wrap the variable name in quotes: "$rightNow""foo bar".)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.