How to modify an AppleScript from edit macro (a template macro) to edit the duplicate of that macro?

hello,

I have a library of template macros. I use the following AppleScript to access the macro after which I duplicate the macro and edit the duplicate which is a bit time consuming.

Is it possible to modify the AppleScript below so that:

  • the macro with the UUSD 4A3A8A81-FE86-4636-82B2-573A43FD213E (just an example) is duplicated
  • the editMacro command applies to the duplicate, not the original macro.

thank you very much

tell application "Keyboard Maestro"
	activate
	editMacro "4A3A8A81-FE86-4636-82B2-573A43FD213E"
end tell

Sure, Keyboard Maestro is fully scriptable.

it's not entirely clear what you are trying to do, but assuming you have an Execute an AppleScript action selected in the editor that has an AppleScript like you show, then this applescript will extract the uid from the xml of the selected action, duplicate the specified macro, and then create the xml of the new action, and copy that into the clipboard - you can then paste it in yourself wherever you want.

I expect I haven't exactly gleaned what you are trying to do, but it should give you a starting point.

tell application "Keyboard Maestro"
	set s to the selection
	set x to xml of item 1 of s
end tell
tell application "Keyboard Maestro Engine"
	set u to search x for "(?s).*editMacro \"(.*?)\".*" replace "$1" with regex
	--	set a to search x for uid replace "newuid"
end tell
--a
tell application "Keyboard Maestro"
	set m to macro id u
	set m2 to duplicate m
	set m2 to item 1 of m2
	set u2 to id of m2
end tell
tell application "Keyboard Maestro Engine"
	set a to search x for u replace u2
end tell
set the clipboard to a
1 Like

thank you very much @peternlewis Long error message, probably too long to post here.

I think I know what you are trying to do. You have a template Macro and you know its UUID. You want to make a duplicate of that Macro and open the duplicate for editing?

The below will do that (replace the UUID number in the Magenta Action with the real template Macro UUID number).

Create duplicate of Template Macro and open Duplicate for editing 1.00v.kmmacros (3.2 KB)

2 Likes

Superb macro. Works perfectly. Thanks very much @Zabobon ! You read my mind !
In addition, the fact you added the UUID in a box at the beginning facilitates entering the UUID when I create variants of the original macro.
Sorry @peternlewis and thanks very much for taking the time to write a script.

1 Like