How to programmatically update an action in another macro?

Here is one way:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set theXML to "<dict>
		<key>ActionName</key>
		<string>Paste Your Script Path in the Action Below</string>
		<key>ActionUID</key>
		<integer>100075176</integer>
		<key>MacroActionType</key>
		<string>SetVariableToText</string>
		<key>Text</key>
		<string>%Variable%PythonScriptsPath%</string>
		<key>Variable</key>
		<string>PythonScriptsPath</string>
	</dict>"

tell application id "com.stairways.keyboardmaestro.editor"
	tell macro "Set Keyboard Maestro ENV Variables"
	make new action with properties {xml:theXML} at beginning
	end tell
end tell

this will add it at the end

	make new action with properties {xml:theXML} at end

More examples and discussion:

How Do I Insert an Action as the First Action in 206 Macros Automatically - Questions & Suggestions - Keyboard Maestro Discourse

If you have other requirements, I'm happy to with your case, if I can.

3 Likes