Convert a Macro UUID to Macro XML Text Without Selecting the Macro in KM Editor

I want to make a subroutine to analyse macro XML for some purpose. The only input is macro UUID.

I can use AppleScript to select the macro then use menu Edit > copy as XML to get macro XML as text. The problem is that it will analyse many macro's XML.

It's not practical to select each of all the macros in editor then do copy as XML one by one. I want it to run in background quietly.

So my question is that if there is a way to convert macro UUID to macro XML?

So I want to make a subroutine:

  • Input macro uuid
  • Output macro xml

I did some search and test, all failed.

Hope people here can help.
Thanks

tell application "Keyboard Maestro"
	xml of macro id "088520CE-CA97-4082-A073-111111111"
end tell
1 Like

Very nice. So easy. Many thanks.

Just same to a reply to Dan's post.

Use AS to do something is so easy. But if you dont know the line. You just dont know it.

So I ask this question here again, is there someone could give us some documents or articles about how to use AppleScript with KM.

I can not find any other info about this topic.

My final:

_ge kme - ext XML by UUID (AS-method) v1.kmmacros (9.4 KB)

Macro Image

image

Search the forum for “learning AppleScript” turns up some useful links. For example:

1 Like

Thanks for reply.
But I don't think it's helpful.
Knowing how to use AppleScript doesn't mean knowing how to use AppleScript with KM.
Writing a lot of AS code cannot make you know you can do 'xml of macro id...'

Taken just by itself that one thread I linked to is limited but it is helpful if you use it with the mass of similar examples you can find here in the forum. I can guarantee that is true because that’s how I learned to use AppleScript with KM. Since all the texts about AppleScript refer primarily to the language, grammar, syntax, etc and very little information about each application that provides AppleScript support you have to spend a lot of time and effort examining the app’s AppleScript dictionary (using for example Script Debugger) which defines what facilities are provided that are accessible via AppleScript and experimenting with it.

BTW - I really dislike AppleScript and I found it very difficult to learn - as I’ve already said somewhere else in this forum. In fact, if I neglect to use AppleScript for longer than a few weeks I find I’ve become “rusty” and the learning begins again :person_shrugging:

I’m sure other users with more experience will have a different tale to tell but my answer to your question is that there’s no book of the sort you’re looking for, no quick fix and no substitute for hard graft.

Look harder :wink:

1 Like

I understand your words. I remembered in Script Debugger, we can check the AS dictionary for a third-party software. But still depends on luck. I havent touch SD for many years.

I hope you understand that I ask this question here because I don't want to ask then know ask then know. I think this is not polite. what I want is just a dictionary.

Since I'm not programmer, try-then-know is not practical.
I will learn to accept that ask-then-know is the only way for me.

still depends on luck

There are no shortcuts or royal roads, alas – sooner or later you will just need to study the Keyboard Maestro osascript scripting dictionaries (one for the editor, one for the engine):

  • Script Editor > File > Open Dictionary > Keyboard Maestro.app
  • Script Editor > File > Open Dictionary > Keyboard Maestro Engine.app

Experimentation, interleaved with questions here, yields the fastest results.

And you have a choice between using the scripting dictionaries in AppleScript or JavaScript.

  1. See the language selector at the top left hand corner of Script Editor.
  2. In the menu bar of the SDEF (Scripting Dictionary) browser there is a selector with a drop-down choice:

Screenshot 2023-05-14 at 11.06.50

Finally, it may be worth trying a copy of Script Debugger which (for AppleScript) has an invaluable object browser – enabling you to see the live application object model (as exposed by the scripting dictionary) with its active values.

It's a very good way of getting insight into what is going on, and what the required code would need to define or update.

只好下点功夫 – 没有捷径 :woman_shrugging:

3 Likes

very instructive. thanks

That approach would work well in this forum. Good luck!

1 Like

The number of google searches I've done that begin with Keyboard Maestro AppleScript and some sort of verb noun soup :sweat_smile: The info is here (or elsewhere!) and if it's not, then an answer is usually quickly supplied here.

2 Likes

What @ComplexPoint said...

I wasn't a programmer when I started studying programming, and I never received a degree in it.

I don't like AppleScript either, but I've used it just about every single day for nearly 30 years – because I do like what I can accomplish with it (and Perl, Python, JavaScript, and a few others...)

Apple has not made it easy to learn AppleScript, so hard work, mentoring, and practice is required. Every app is different and requires learning at least some new syntax.

Serious scripters hang out at MacScripter.net and the Script Debugger Forum – and ask questions when they're stuck.

Asking people to do your work for you is not polite – but asking questions as part of the learning process is a Human imperative...

2 Likes

Script Editor can show the dictionary of scriptable applications, so it is a matter of looking at the dictionary to see what is available.

Or just post here and ask and someone will tell you.

3 Likes

Great info :smiley:

Hi, @Yu_Cai. You've received lots of great advice from the giants in the forum. All above have helped me! :grinning:

When I was first learning, I found this wiki page to be very helpful: Scripting the Keyboard Maestro editor [Keyboard Maestro Wiki].

4 Likes