What Is the Status of the Paste XML Action Feature?

I'm confused about the status of pasting XML actions and I'm very enthused about the concept. Can someone clarify what the real status of this features is?

In July 2017, Peter wrote:

It was listed as a feature of Keyboard Maestro 8 in July 2017. Yay. The feature was implemented over three years ago. Whoopie!

Then in October 2019, b1w2 asked and Peter answered:

So the feature was never actually implemented, despite being announced as done. And it took 27 months for that to be noticed. Maybe it's not as useful as I imagine.

Or what?

If you are wanting to get the XML of an Action, make mods to that XML, then insert as a new Action, you might try this workaround:

  1. Export Action as a .kmactions file (menu File > Export Actions)
  2. This is a XML file. Mod as you like
  3. Import modified file: menu File > Import Actions

image

As I had originally said, it was done for the next version. I just apparently didn't do it right. (I was a bit surprised that I'd said that and it doesn't work, as I don't normally say things about the next version uless I have actually done them already).

It should be working in the next version.

2 Likes

I’ve been using some code shown by @ccstone here to insert XML versions of custom actions of mine into macros I am working on. I can envisage this being altered relatively easily to work with the XML if it is stored in a clipboard or KM variable, rather than being embedded in the code so it could then be considered a way to paste XML actions until it is implemented natively in KM.

Is this the kind of thing you had in mind when wishing to paste XML actions?

2 Likes

Thanks @tiffle. I haven't dug into @ccstone's post enough yet to answer your question. He does have a link to the Late Night Software forum as a resource for AppleScript, which may prove to be invaluable.

While I imagine I may eventually have wide ranging uses for being able to automatically modify or generate KeyBoard Maestro macros, my immediate desire is this:

I typically have 21 desktops between my MacBook Pro monitor and my external monitor. Email, Facebook, Money and Insurance, Health, Project Planning, Research, Video watching, Archiving, as well as several dedicated to specific projects, sometimes two for a multifaceted project.

KBM has totally solved my issue of being able to have enough hotkeys to switch between them. Using the free app CurrentKey Stats I assign hotkeys to my most commonly used ones (I suppose I could use KBM, but CK was there first) and for everything else I a KBM hotkey that pops up a menu of the desktop names.

Virtually every task management app that I have tried, One Note, Evernote, Trello, OmniPlan, etc. has a severe drawback in this environment in that when I have to reboot the system, all the open TMA windows end up on the first desktop after a reboot. So originally I was thinking of ways to automate moving them all back where they belong. But that's not necessary at the moment.

I recently discovered that TextEdit windows will automatically be reopened in their original desktops after a reboot, so I'm now working on having Status and To Do files in TextEdit in most desktops to keep track of what's in progress and what's next in the various contexts.

I am looking at various housekeeping ideas where the same macro would have a different effect, depending on which desktop was active when it was invoked. For instance, my Desktop Status macro would determine which desktop I was on and open the appropriate TextEdit file if it was not already open, and move it to the appropriate position on the screen.

Since I might need the triggered macro to choose between 21 possibilities, there are likely to be blocks of KBM code that get repeated 21 times with only minor variations. Having a macro to do those edits might be very handy.

Since I sometimes rearrange the order of desktops to make moving files back and forth simpler, and the names sometimes change and my usage evolves, I can't count on the ways to tell the difference between desktops being fixed in stone. If they need to be hardcoded at any level, and think they might be, I would like to be able to in some way automatically massage them to update them as needed. At the very least, I'd like to run the existing macros through a comparison with the current list of desktop names to determine which macros need updating, and where.

For instance, just today I change the name of my Projects desktop to Project Planning. I need to update my KBM hotkey menu to match. I'd love to be able to run a macro to do that updating. All the info needed is right there, accessible to macros through scripts and CK's AppleScript hooks, but for now I have to do it by hand, taking dozens of thoughtful steps.

This is all future planning. Most of this hasn't been built yet, but the more I enjoy having different Status and To Do lists available on each desktop, the more I expect to want to be able to automate massaging macro definitions.

1 Like

Repeatedly, above and elsewhere, people have made similar suggestions:

But I'm warry of breaking things, so I want to ensure that "Mod as you like" is actually reasonable. For instance, when I look at an exported XML file of a single, short macro, I see some XML values that I have questions about:
:black_small_square: Creation Date β€” a β€œreal” value of 9+6 digits. One of these for the Group, one for each macro.
:black_small_square: ActionUID β€” each action in the macro has an integer assigned.
:black_small_square: UID β€” the macro and the group each get one, of the form:
5779F029-64BE-4931-ACDC-B3F6605493AC
:black_small_square: ToggleMacroUID β€” one for the group, same form as UID
:black_small_square: Comment > StyledText is 27 lines of encoded data, even when the comment text field is empty.

All of the above XML values are things that I cannot easily fill in myself. Do I leave them as they are for the system to automatically update, edit them to be blank for the system to fill in, completely remove the key and the value for the system to replace for me, or what?

Hey August

let me throw some thoughts in here...

If I remember it right the Date Value in the Macro / Macro Group XML is a UNIX Timestamp which is automatically created by KM.

  • It could be read and converted to a real Date-Time Stamp that you can use for example in your Macro Release Notes.

  • You could also change that Value outside KM used on an Exported Macro or Macro Group XML File if you want to convering the File date of the Exported file to a Unix Time Stamp and replacing the original Value in the XML File.

    • NOTE: Inside KM this will not be possible

The Value of the ActionUID/ActionUUID is an absolute unique integer - which - if I remember it right - you could store in a Dictionary with all dependencies for it (Action Infos & the Macro it is in) But that is very overkill

Dan (@DanThomas) somewhere wrote that you can use it if you run the Action of your choice in an Execute AppleScript or JXA Action - but you dont need that Integer Value if the Action is scripted since the Integer is changed every time the scripted Action is executed.

If you want to insert a specific Action using Code like AppleScript or JXA into a Macro using the Action's XML - You don't really need that Value either - KM does the Job for you.

If You are willing to have a unique and documented Value to find that Action whenever you want to - You Need a workflow which

  • a) creates a database that stores all ActionUID's (including other nessesary Infos)
  • b) fetches all of them to create a new unique one and creates that Value for you
  • c) adds that new ActionUID to that Database
  • d) the ActionUID is used to create and insert the Action into your Macro.

For Creating Macros with a UUID the whole thing is quite similar. You dont really need the UUID until you create for example One Main Macro and two linked Submacros on the Fly using AppleScript or JXA.

If there are existing Macros Involved you have to examine their UUID's to use them - If the Macros are new ones you must esure that the UUID's are unique otherwise KM would create the UUID's for you and you would have to link the macros together by hand.

If you want to toggle Macros or Macro Groups there is the same like I wrote it for MacroUUIDs.

You can also create a searchable Pick List for your Toggle Macro or Toggle Macro Group Acrions to insert in your currently selected Macro by using Dan's fabolous Pick 'Execute a Macro' as a starting point using a custom List.
You can also try to combine this Pick-List with the base of @ccstone's AppleScript Code (thanx Chris) which was mentioned by @tiffle before.

There is a Macro provided by Chris (@ccstone) about an attributed Action (Comment)
which should give you a starting point on this ....

Maybe I've forgot something here maybe not ...

Greetings from Germany

Tobias

Don't worry about any of those fields. They will be created or modified as needed.

The best way to modify the XML is to use something like this macro of mine:

Just use it to edit action or actions you want to modify, delete the old actions, and paste the modified actions in. If you mess up anything, they'll refuse to get pasted back in. You can always use the editor's Undo if you need to. And you can work on a copy of the macro if you prefer.

Personally, I use KMET all the time, although I usually work on the JSON version rather than the XML because it's easier to understand the structure.

Thanks Tobias,

That is more information than I was asking for, but I love having all the extra details. I don't expect to be actually using any of those values, not if I can help it, I was asking what I can ignore and how to ignore them: leave them as is, leave them empty, or remove the value entirely.

Thanks for the explanation:

Wrestling with UUIDs does seem fun or fruitful at the moment, but I appreciate your notes. Since it seems I am frequently imagining uses, tools, and workflows that go beyond the original design capabilities, this may come in handy at some point.

Thanks also for the tip to Dan's Pick and Insert 'Execute a Macro'. I had seen that before but not looked deeply and so I had not thought of that as a way to implement my idea. My impression is that it's a tool for writing macros and I want to automatically generate a macro group to create a Conflict Menu from a generated text list of options, so it may not be operating at the contextual level that I'm working on right now.

Thanks again for the deep dive,
August

Thanks Dan,

That's the impression I got from Tobias' notes and it's nice to have confirmation that it "just works".

I, too, prefer editing JSON if I'm doing it manually. And writing scripts to automate the editing is easier too. Years ago I spent a lot of time writing raw HTML so reading XML is not that hard. I was presuming it would be someow "better" because that's the native format, but if KM can export and import JSON macros and groups, that's the way I'll go.

I will give the KMET macros a serious look.

My idea is to have a group where every macro has the same hotkey and thus the whole group creates a conflict palette. My current thought is to leave each current group of macros as they are when I update them and simply disable them when I import the modified set. I was thinking that if I include the date-time in the group name, I can manually revert to an older set at any time, until I see that they can be deleted.

Is there a KM way to disable a group from within a macro? How about delete a group? Of course given the exact name of the group.

I imagine it would be in the form of running an AppleScript script that said something like "tell application KeyboardMaestro ...". Are the commands that KM accepts from AppleScript documented anywhere?

Thanks,
August

To be clear, KM can't do that. But my macros can.

As for storing previous versions of your macro, you could take a look at this macro set from me:

You can store the macros as JSON or XML, and restore them any time you want to. I also use Git for version control.

Yes, you can disable groups from within a macro. Just look for actions that talk about enabling or disabling macros, and they can also do Groups.

Yes, you can delete them using AppleScript (or JXA). You do it by UUID, not by name, because names don't have to be unique. I'm sure if you did some searching in the forum, you can find examples.

Ah, THAT is the reason I was presuming that I would have to use XML. Thanks!

1 Like

You're welcome, August

The thoughts I had writing out these Infos to you were somewhat like "maybe he doesn't know that ? Well, for the things he want to do it seems to be better if he knows that.. - Sometimes it is better to have more Infos..."

And I am very grateful that my long notes will be helpful for you in some cases - but not only for you - for every one who will come to this thread in the future.

Since Dan posted about his KMET Macros, I knew I forgot something ... but that only shows that I am a human :joy: :joy: :joy:

For this thought you have - here is an additional thought that I have vor you:

  • there is also this Macro from Dan - which I use quite often - Go To Group by Name.
  • I would use it as a starting point and add additional functionallity to it with a custom Button named "Options".
  • Pressing that button could throw a Prompt where I then could disable the Group and choose between Editing as XML or JSON using KMET with a predefined String like "edited with KMET & todays date" which then can be added to the Group Name String in the XML or JSON in BBEdit.

Something to know here: Since the Macro returns the Group UUID you would have to script the Disable Macro Group Action with either AppleScript or JXA.

The Next thing is that you would have to know how the Action is working if it uses Group Name and UUID then you need a custom List generated fron JSON so that you can parse both from your selection.

I think this quite a nice approach - because of that I think I'll do this for my self....

That's all I have for now...

Greetings from Germany

Tobias

1 Like