See:
Quoting is always a pain in the neck. In order to understand it, you have to understand what happens at each level of the processing.
Thankfully, in a script, Keyboard Maestro itself does not do any processing, so that is one less place for confusion.
With shell commands, the important thing to understand is that, with only a few exceptional programs, it is not the command that does the processing, it is the shell (bash usually, although there are many shells).
So it is the bash tool that s…
and
Hey JM,
That’s pretty much it I do believe.
For readability I prefer to write AppleScripts embedded in shell scripts like this:
read -r -d '' theAppleScript <<'EOF'
tell application "Keyboard Maestro Engine"
tell variable "pathStr"
if it exists then
return its value
else
return "Error → Keyboard Maestro variable “pathStr” does not exist!"
end if
end tell
end tell
EOF
osascript -e "$theAppleScript";
You don’t have to fight…
However, may I ask: Why are you using a shell script with osascript?
Using a KM Action "[Execute AppleScript](https://wiki.keyboardmaestro.com/action/Execute_an_AppleScript)" is much simpler, and you can avoid the quoting issues.
1 Like