[Solved] Mac - Trigger Keyboard Maestro?

Is it possible (and if it is how) to trigger a specific Keyboard Maestro script from Drafts Action?

When you look at a Keyboard Maestro action you should see options to trigger via URL. Have your Drafts action open the URL and it will trigger the action.

Alternatively, you can trigger Keyboard Maestro macros by AppleScript, and Drafts does include support for running AppleScript in actions.

Hopefully that gives you at least one option with the right level of control for what you want to do.

1 Like

I can’t figure out what am I doing wrong as it works if executed from Apple Script Editor.

The operation couldn’t be completed. /Users/slyfox/Library/Application Scripts/com.agiletortoise.Drafts-OSX/Temp/applescript-625610239.051946.scpt: execution error: No error. (-1708)

Script:

-- ignoring application responses

tell application “Keyboard Maestro Engine”
do script “Email Report”
end tell
– end ignoring

Script name in KM: Email Report

Screen Shot 2020-10-28 at 4.39.56 PM

I think I figure it out…

I had to add on execute(draft) at the top and close it with end execute

Is this correct?

on execute(draft)
– ignoring application responses
tell application “Keyboard Maestro Engine”
do script “Email Report”
end tell
– end ignoring
end execute

I just gave it a quick try with one of my test macros. I copied the AppleScript trigger for it and pasted it into the script execution block in an action with a single AppleScript step.

on execute(draft)
-- ignoring application responses
tell application "Keyboard Maestro Engine"
	do script "53DE40B4-3C99-45D1-B775-83988465B52D"
	-- or: do script "Alert 01"
	-- or: do script "53DE40B4-3C99-45D1-B775-83988465B52D" with parameter "Whatever"
end tell
-- end ignoring
end execute

I then ran the action.

I got prompted to authorise Drafts’ control of Keyboard Maestro.

2020-10-28-20.50.41

That then created the top entry in my Automation security settings as shown here.

The macro executed successfully and showed my test notification.


1. Add back the execution instruction

In the Drafts documentation for the AppleScript step, it says.

Each AppleScript used should contain an execute subroutine, which takes a single parameters, which will contain a record of values about the current draft, including properties the following properties:

So I would definitely add those execute lines back in.

2. Check permissions

After you have done the above and run it, hopefully it will prompt you for control, but I would suggest that in any case it would be worth checking that Drafts has/gets the appropriate security permission for automating Keyboard Maestro?


Hope that helps.

For the sake of completeness I also tried running via the URL.

2020-10-28-21.01.10

That also worked fine for me, including when I disabled the automation option for Drafts to control Keyboard Maestro; the URL sits outside that automation space.

I think the URL remains the simplest trigger to add and maintain, but the AppleScript option will probably give you more control options in your action if you are doing things like varying the number and names of macros called.

Thank you. I originally looked at https://scripting.getdrafts.com/classes/applescript

The link above does not have the instructions for Each AppleScript used should contain an execute subroutine,

I will also try the URL.