How Do I Get KM Variable in Shell Script from other Apps?

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 with the shell's quoting conventions either.

-Chris

2 Likes