Improve Export as Folder macro by adding ZIP and Delete Folder

Hello,

I created the attached macro to backup to a folder all created and modified macros during the past week using a "created or modified in the past week" smart group I created.

I use it often when I am working editing and creating macros, and it works fine.

After running the macro, I open the folder (easy to implement in the macro) and
1- zip the folder
2- delete the initial folder

To save time, I would like add the following to the end of my macro
1- zip the newly created folder
2- if it is risk free, delete the initial folder

thank you very much

ZZ KBM Forum Backup Macros Created Mofidied PAST WEEK.kmmacros (27.8 KB)

1 Like

Hi, @ronald. I downloaded your macro to try it out, but I don't have the macro that is called in the first action.

Would you please upload it? Thanks!

1 Like

I am very sorry. thank you very much

Go To Macros Created or Modified PAST WEEK KBM SMART Group.kmmacros (5.7 KB)

1 Like

Thanks, @ronald.

I like the way you have leveraged built-in features of Keyboard Maestro to complete the backup.

Thanks for sharing.

1 Like

thank you. I use insert text instead of UUID because it's a smart group and they don't have UUIDs as far as I understand.

Smart Groups have UUIDs -- it's actually the UUID that is the identifier, the name is just fluff.

I'm not sure how it would help, though -- unless you were going to use something like

image

...to select it?

1 Like

this is what I use to go to a normal macro group.

Where do you find the UUID of a smart macro group ? It's not in its context menu (contrary to normal macro groups).

thank you for your reply.

It's not in the right-click context menu but it is in the regular top menu item Edit>Copy as>Copy UUID

I have noticed a few differences between the context menu "Copy as" vs the top menu "Copy as". For example, copying a Macro's XML returns a different result, depending on which method is used (menu "Copy as XML" gives an XML that can be imported as a Macro, whilst context "Copy as XML" gives a version of XML that cannot be used to import a Macro).

As a result I have stopped using the context version of "Copy as" and now always use the top menu version. Not sure why there are these differences and I have been meaning to ask @peternlewis

1 Like

the time I wasted trying to figure it out !

I will do like you in the future.

thanks very much !

1 Like

Happy New Year @ronald !

1 Like

I discovered something by accident today and started using it to accelerate my workflow.

If you copy an action as XML → with that XML you create a typinator shortcut, and repeat for most commonly used actions.

If you create a new macro and add a comment at the top, you can quickly (by writing the typinator abbreviation inside the comment) generate a series of actions to create the macro.

Happy New Year @Zabobon @Nige_S @_jims !

3 Likes

I have been doing a similar thing. Set the Action up as I like, including its color, etc. Copy it as XML then make a Macro that just Inserts Text by Pasting that XML text. I then give the Macro a shortcut and have it in a Group that is only active in Keyboard Maestro. For example P inserts a Prompt for User Input Action, V inserts a Set Variable Action, V inserts a Set Variable to Calculation I inserts an If Then Else, S inserts a Switch Case Action etc. Basically all the Actioins I find I am using all the time. It works really well.

3 Likes

much better than my method. Faster and smarter. I will adopt your method and put mine in the garbage. Thanks VERY much !! It will keep me busy tomorrow.
I know that it's possible to see the most commonly used macros (view → sort). Is there the equivalent for actions? I will be creating a macro group like yours and it would make things faster if I could determine which actions I use the most.

If you like the way "Compress" works in Finder, this replicates it:

image

...where Local_source is the variable holding the full path to folder you want to compress.

Command is:

ditto -c -k --sequesterRsrc --keepParent  "${KMVAR_Local_source}" "${KMVAR_Local_source}".zip

Since you've stored the source path in a variable it's easy enough to delete later:

image

What I would suggest is that you change your macro so you build your export file path then use it, instead of building it as part of the "Paste" action. That way you'll have a known path to work with, and won't have problems if you export at 11:59 and try to compress/delete at 12:00!

4 Likes

good point. I will work on it tomorrow and give you an update. Thanks very much ! I have learned so much with this post !

If it helps get you started here is one my Macros that you can use as a template.

Create Action - For Each.kmmacros (4.3 KB)

One thing to be aware of when you are making one of these Macros. If you simply paste an Action's XML into the Insert Text by Pasting Action you will actually just create a new Action in the macro you are working in. So, you first need to "disable" the XML text you are pasting, by opening it in a text editor and adding some random character to the start (I usually add a "1"). This text can then be safely pasted into the Action without anything happening. I then delete the "1" at the start to make the XML a working XML again.

XML pasted in with "1" at start to disable it making a new Action in the Macro during the paste operation.
image
XML with the "1" removed so, the Macro will work.
image

2 Likes

Since only the first-level <dict> and its contents are required, you can also paste into a text editor, copy from there everything from after the < of the first <dict> to the end of the last </dict>:

dict>
	<key>ActionUID</key>
	<integer>14699365</integer>
	<key>Actions</key>
	<array/>
	<key>Collections</key>
	<dict>
		<key>CollectionList</key>
		<array/>
	</dict>
	<key>MacroActionType</key>
	<string>For</string>
	<key>TimeOutAbortsMacro</key>
	<true/>
	<key>Variable</key>
	<string>Local_</string>
</dict>

...then in your new "Insert Text" action type a < and then paste to give:

image

1 Like

Hi, @ronald. I added the zip capability and a few other features.

Here are the settings...

Keyboard Maestro Export


And here's the Prompt With List for Smart Group selection...


Here's an example zip file name...

2025-01-02 0034_07 KM Smart Group – Cre Mod 7d (128 macros).zip


[ I moved the download to to the Macro Library category: Zip a Smart Group. ]

1 Like

I created this macro to pick up actions as I go along. I paste the clipboard into your macro which I renamed TEMPLATE and which I duplicate.
I started using your method and it's absolutely great ! thank you very much !

_Copy KBM Action XML → Inactivate it with Prefix 1.kmmacros (4.6 KB)

[details=“Screenshot (click to expand/collapse)"]


[/details]

1 Like

There is no good reason. They should be the same, but aren't always. The most annoying was when you got different images or XML depending on which one you chose, but hopefully that is not the case.

The contextual menu should be a simple subset of the menus, but it isn't quite that simple.

3 Likes