Help with hardcoding macro UUIDs & handling a second import that changes the UUIDs

As many of you know, if you have a macro set installed, and you import a second version of the macros from a KMMacros file, the imported macros get new UUIDs, and KM is smart enough to make sure any macros imported at the same time that reference other imported macros get their references updated at the same time.

If you don't understand this, you probably can't help me with my issue, so ignore this topic. ;p

Here's my problem: I'm triggering some of these macros from JXA and/or JS, which means I have to hard-code the macros' UUIDs. And of course the import process doesn't update these hard-coded UUIDs to the new UUIDs.

My question is, is there anything I can do about this? I could use the macro names instead, but 1) the names could get changed and 2) that wouldn't solve having two macros with the same names installed.

When I start any of my macros, they all call a macro that sets up various Instance variables. This macro would be a good place to solve this problem, if possible.

I need some way to have the macros that I've hard-coded the UUIDs for to be referenced by KM actions that will get updated during the import process, and then extract the UUIDs from those actions.

I have some ideas using JXA, but I'm hoping someone here as some other ideas. Thanks.

NOTE: I've added a feature request for an action like this:

image

Hard-code your own UUIDs into each macro (Comment? Local variable statement? Anything you can easily search for) and then, post-import, build a hash table relating your UUIDs to the "real" macro IDs?

Actually, that's something I've thought of, but I think something like this might be better:

image

 
This will automatically get updated to the new UUIDs during import.

So if I add it to the top of my "Get Options" macro, then I can write some JXA to inspect its XML (or JSON, in this example):

[
	{
		"MacroActionType": "IfThenElse",
		"ElseActions": [],
		"Conditions": {
			"ConditionListMatch": "All",
			"ConditionList": [
				{
					"MacroUID": "7BAA6A64-B769-48D9-9A89-64AA8921BBDD",
					"ConditionType": "Macro",
					"MacroConditionType": "IsEnabled"
				}
			]
		},
		"ThenActions": [],
		"TimeOutAbortsMacro": true,
		"ActionUID": 15871049
	}
]

If I have multiple macros I need the UUIDs for, I'll just know what order they are in the action.

I can even disable the action, and it should still work.

What do you think?

I think I don't know enough about how import works :wink:

If the action is reliably correctly updated to resolve to the new UUIDs during import (and I don't see why it wouldn't be) and either a) the action's Conditions remain in the same order after import, or b) you are happy to one specially-named "If..." per macro, then I can't see why it wouldn't work...

Famous last words, those!

1 Like