How to Create a Macro in Its Own Macro Group via XML?

Hi,

I'm trying to make macro that sets TriggerValue by its macro name.

I'm very new to XML so, by edit and reference scripts in the forum I could generate the macro with prompt input, but I cannot set the macro group just type its name by text.

KM keeps creating a new macro group (in this case group name is test).

How could I force set XML to create a macro in a specific macro group?

Since the macro image doesn't show all the XML text, I attached my scripts.

Any tips with this?

Thank you.


create new macro triggervalue by its name.kmmacros (5.1 KB)




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>Activate</key>
		<string>Normal</string>
		<key>Macros</key>
		<array>
			<dict>
				<key>Actions</key>
				<array>
	<dict>
		<key>ActionUID</key>
		<integer>12492347</integer>
		<key>Asynchronously</key>
		<false/>
		<key>MacroActionType</key>
		<string>ExecuteMacro</string>
		<key>MacroUID</key>
		<string>27DD4AB7-AF62-4863-BA42-DB532411632F</string>
		<key>TimeOutAbortsMacro</key>
		<true/>
		<key>UseParameter</key>
		<false/>
	</dict>
				</array>
				<key>Name</key>
				<string>%Variable%Local__name%</string>
				<key>Triggers</key>
				<array>
				</array>
			</dict>
		</array>
		<key>Name</key>
		<string>test</string>
	</dict>
</array>
</plist>

You don't -- you do it at the import stage:

tell application "Keyboard Maestro"
	tell macro group "Imported Macros" to importMacros e
end tell

I don't really understand what you are trying to do here. Do you just want to create a new macro with a name you supply, and nothing else? If so, don't mess around with XML and importing, just use a simple AppleScript:

set macroName to text returned of (display dialog "Name of new macro:" default answer "My New Macro")

tell application "Keyboard Maestro"
	tell macro group "Plugins" to make new macro with properties {name:macroName}
end tell

That uses an AS display dialog to prompt for the name, but you could easily pass the name in from a KM variable.

2 Likes

Hey,

Thanks for reply.

The thing I tried to do was create new macro inside its own macro group with XML.

I think it's tricky because the XML script contains text like %ExecuteMacro% or %TriggerValue%.

I just want them paste as plain text not treat like variable.

I'll give your solution a shot.

Thanks again

Right. But to repeat the question that was asked is: Why are you taking the "import XML" approach to creating macros.

It seems to me, too, there's little point unless you're generating substantially custom XML - for several different macros.

(I'm interested in the technique, as much as anything.)