Call KBM Macro from macOS OSascript?

I'd seen this question before and frankly, I didn't quite understand the answer, but I went ahead and fixed it myself in a pretty simple way. I just used "osascript -e 'script-UUID' " and it worked fine.

Suddenly later that session, I ran it from the command line and got
syntax error: Expected end of line but found unknown token. (-2741)

Then I used osascript -e "tell application 'Keyboard Maestro Engine'\n do script '34007B18-D3C6-4 2F8-BEC6-9FBFCB11EF7B' \nend tell"

Now, given that someone supposedly answered this issue before and got something working, could you please give me some example of how I would call a KBM macro from BASH ????


Hey @gmark,

I expect the easiest way is to use the Keyboard Maestro URL-scheme.

#!/usr/bin/env bash
open kmtrigger://macro=AFB1EE80-3A76-4E58-A0E8-4C742CBC5C5F

The last parameter is the UUID of the macro.

If/when you run AppleScript from Bash I recommend making it readable. One-liners may seem streamlined, but when you have to maintain them they can be very hard to read.

#!/usr/bin/env bash

read -r -d '' asCmdStr <<'EOF'
   tell application "Keyboard Maestro Engine"
      do script "AFB1EE80-3A76-4E58-A0E8-4C742CBC5C5F"
   end tell

osascript -e "$asCmdStr"



I'm not sure where the cult of the one-liner started,

( misintepretation of phrases like it's just a one liner ? )

but it's never kind to give people the impression that
some kind of slightly mysterious credit attaches to
expressing things in a single line ...

(If Lincoln had done that to the Gettysburg address we would never have heard of it, and even if he had somehow managed not to lose or tangle the very long piece of string or sellotape on which it was written, he would have run out of breath before getting half way)

1 Like