Wrote a Macro to Export as Trigger File → would like to create a Batch Export Multiple Macros as Trigger File Variant?

Thanks to the help of the brilliant @Nige_S and @Zabobon, I use a folder in the dock as another means of triggering macros.

The only "problem" is that there does not seem to be an option to batch export macros as trigger files, and it's a bit tedious to export them one by one.

I wrote the following macro to export a single macro as a trigger file with date time stamp.

Export Macro as Trigger File.kmmacros (9.1 KB)

My problem is to create a variant which would handle all selected macros, in vein of the excellent group of macros created by @gglick to search and replace in macro names and delete triggers.

Copy, Paste, and Batch-Delete Triggers - Macro Library - Keyboard Maestro Discourse

Could a similar approach be used to batch export as trigger files ?

thank you

1 Like

Hello @tiffle. just to let you know I made extensive edits to my post after you read it.

I guess that was your wayward assistant’s responsibility😉

1 Like

very funny !

AppleScript to the rescue! I can't fully test, as your GUI scripting doesn't work for me, but this should get the selected macros in the frontmost KM window then select them one at a time and run your export macro.

As written you can run it from Script Editor, but you should be able to just drop it into an "Execute AppleScript" action and run it with a hotkey.

Edit to add:
Since @Zabobon's confirmed that the AppleScript does indeed wait for the macro to complete before moving on to the next item in the list, we're back to the original script:

tell application "Keyboard Maestro"
	activate
	set theList to (get selection)
	repeat with eachItem in theList
		select eachItem
		tell application "Keyboard Maestro Engine" to do script "Export Macro as Trigger File KM Forum version"
	end repeat
end tell
Previous edit, in case the 'pause' version is needed

Just had an horrible thought -- as written the script will probably spam the Engine with do scripts faster than it processes macros, meaning the selection will be wrong. This is a quick edit so you should be able to run the script from Script Editor -- I'm sure there'll be a way to pause when running as a KM action but that'll need a bit more work...

tell application "Keyboard Maestro"
	activate
	set theList to (get selection)
	repeat with eachItem in theList
		select eachItem
		tell application "Keyboard Maestro Engine"
			do script "Export Macro as Trigger File KM Forum version"
			repeat while executing
				delay 1
			end repeat
		end tell
	end repeat
end tell
1 Like

Actually your first AppleScript ran fine for me (running from a Keyboard Maestro Execute AppleScript Action) and it respected whatever pauses were in the Macro it was batch running before moving on to the next selected item. So, it didn't trip over itself.

1 Like

Thanks for checking, @Zabobon -- must have been the "Export" macro erroring that made it look like it was running async. Post back to as it was...

Hi and thanks very much for the AppleScript

Error don't know what the next step is.

Engine LOG error
2022-10-22 15:03:48 Execute an AppleScript failed with script error: text-script:177:217: execution error: Keyboard Maestro Engine got an error: do script found no macros with a matching name (macros must be enabled, and in macro groups that are enabled and currently active). (-1). Macro “Export BATCH EXPORT SELECTED Macros as Trigger Files” cancelled (while executing Execute AppleScript).

showing macro name
2022-10-22_15-05-18

batch export macro

Check the macro's Group's "Activation" settings -- IIRC the macro you uploaded to the Forum was in a Group that was palette-dependant, and I had to make it "Always activated".

1 Like

Finally, I understand. Everything (all macros including the script and the macro it triggers) must be in the global macro group (or any group always active). They were in the KM Group.

You are a genius! No other word. Thanks very very much.

Your idea of a folder of aliases in the dock is great. I often use it. Thanks to you, it will be easier to populate.