MACRO: Zip Smart Group(s), v3.0

TRIGGERED NORMALLY

If the macro is triggered normally, a Prompt With List like the following will appear. By default, all Smart Groups are listed. The list can be limited using an optional macro setting.



TRIGGERED FROM ANOTHER MACRO

If the macro is triggered from another macro using the Execute a Macro action and one or more Smart Groups are specified (UUID or Name), the above Prompt With List is skipped and the backups immediately commence. As each backup completes, dialogs like the following appear.




BACKGROUND

If you are looking for a full-featured back-up tool, I suggest you check out:

There may be others that I've missed.

This macro was inspired by @ronald's idea in this thread.

DESCRIPTION

This macro provide a quick and simple method to back-up the macros listed in any Smart Group. All exported macros will be zipped into a single archive. The archive name includes:

  • Date & time
  • KM Smart Group –
  • Smart Group name
  • macro count
  • zip extension

For example,

2025-01-05 2249_04 KM Smart Group – 3-Cre Mod 2d (45 macros).zip


This macro uses the following Keyboard Maestro Editor native feature: File > Export Export as Folder.... As mentioned above, this macro then subsequently zips the newly created folder.

One nice feature of Export Export as Folder... is that it maintains the Macro Group hierarchy when the macros are exported. Thus, even though this macro keys off Smart Groups, the backup has a subfolder for the parent Macro Group of each macro backed up.


Since the macro is quick and simple, it's an ideal tool to use during macro development.

For example, you could create a Smart Group named Cre Mod 4h with two match strings cre:4h and mod:4h. Then run this macro and select that Smart Group. In just a few seconds you'd have a back-up of all macros created or modified within the last 4 hours, all saved within a single zip file.

Since the macro provides an option to reveal the archive after creation, it becomes very easy to manage the archive files.

SETTINGS

local_BackupRootPath
All backup zip files will be be written to this folder. If they do not exist, the sub folders in the path (below home: ~) will be created by the macro. The default is:

~/Documents/Automation/_Keyboard Maestro/Backups

If this path is not specified, the archive file will be written to:

~/Downloads

local_SmartGroupPatterns
This variable can be optionally used to limit the Smart Groups displayed for backup. Each line is used as a Regular Expression pattern.

If nothing is specified (the default), the macro will provide an option to back up any of the Smart Groups.


USING ANOTHER MACRO TO TRIGGER

This macro can be triggered using the Execute a Macro action in another macro and the Smart Group(s) are specified using the With Parameter, one Smart Group Name or UUID per line. In this mode, the interactive list of Smart Groups (via a Prompt With List) will not be displayed, thus local_SmartGroupPatterns does not apply.

In addition to the Execute a Macro action, the primary macro can be triggered using AppleScript within or outside Keyboard Maestro. Here's an example zipping two Smart Groups:

-- Zip Smart Group(s)

property theP : "1-Cre Mod 1h
F542D717-B0F7-4361-B44B-E16892686B67"

tell application "Keyboard Maestro Engine"
	do script "43C753A4-C71C-45DD-9F65-346DB1A8350A" with parameter theP
end tell

Note that in this example a Smart Group name is used for the first Smart Group, and a UUID is used for the second. (See property theP.)

TESTED WITH

• Keyboard Maestro 11.0.3
• Sequoia 15.3 (24D5034f)/MacBookPro18,2
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

( expand / collapse )

1.0 - initial version

2.0
a) Macro can now be called using the Execute a Macro action and the Smart Group(s) can be specified using the With Parameter, one Smart Group Name or UUID per line.

b) Macro name changed from Zip a Smart Group to Zip Smart Group(s).

3.0
a) Added feedback dialog if an empty Smart Group is selected.

b) Reduced pause durations. For those using a very slow mac, it might be necessary to increase them.

c) Improved efficiency and readability of the JXA code that gathers the Smart Group information.

d) Fixed a dialog typographical error.


PRIMARY MACRO

Download: Zip Smart Group(s).kmmacros (75 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 15.3 (24D5034f) PRE-RELEASE SEED SOFTWARE
  • Keyboard Maestro v11.0.3

EXAMPLE CALLING MACRO

Download: 𝘊𝘢𝘭𝘭 Zip Smart Group(s).kmmacros (2.9 KB)

Macro-Image


3 Likes

I've updated the OP with Version 2.0 of Zip Smart Group(s):

  • Macro can now be called using the Execute a Macro action and the Smart Group(s) can be specified using the With Parameter, one Smart Group Name or UUID per line.

  • Macro name changed from Zip a Smart Group to Zip Smart Group(s) .

3 Likes

I've updated the OP with Version 3.0 of Zip Smart Group(s):

  • Added feedback dialog if an empty Smart Group is selected.

  • Reduced pause durations. For those using a very slow mac, it might be necessary to increase them.

  • Improved efficiency and readability of the JXA code that gathers the Smart Group information.

  • Fixed a dialog typographical error.

In the MacroBackerUpper thread, @ronald had this request:

Since sets of macros like these can be be created with Smart Groups, I suggested that @ronald use MacroBackerUpper at a lower frequency, then use Zip Smart Group(s) to address the above requirements.


Using the Search Strings syntax, here are the Smart Group definitions for each set...

1. modified or changed created in the past x number of days

I suspect @ronald intended to specify created, not changed, thus for five days, this is simply:

mod:5d
cre:5d

2. all macros in selected macro group

In most cases, this is simply:

gr:"group_name"

But I've found in some cases it's a bit trickier. For example, if you have the following three Macro Groups:

⋮Notes
⋮Notes ⚪️
⋮Notes ☆

And if you want the macros in ⋮Notes (only), one might think that this definition would work:

gr:"⋮Notes"

But the above is a bit greedier than I expected: it includes macros from all three Macro Groups. To limit the Smart Group to the first Macro Group, this definition can be used:

gr:"⋮Notes" -gr:"⋮Notes ⚪️" -gr:"⋮Notes ☆"

1 Like

Hello @_jims ,

Your macro is superb ! I spent a few hours playing around with it.

Just a few points. Take my comments with a grain of salt: you are the expert and I am a dilettante.

1- sometimes it worked, other times not. The problem was that I chose a dropbox folder for backup, and dropbox forbids certain characters in the filename.
All works fine with non dropbox folders. I tested many times.
This is a known issue with KM export as folder. I had forgotten about it.
Should the documentation suggest a non dropbox folder ?

2- when the macro is finished running, I am in KM, in the smart group being backed up with all macros in that smart group actively selected. Based on past experience, I have found this to be dangerous (for me). One accidental delete and it's a disaster. Once again a similar situation has happened to me, so it's not just my imagination.
A simple solution is simply to insert a type "→ " action at that point. I do it manually, but it could be included in the macro.

3- I can't figure out why the macro ends in KM as above. It's as if the whole post backup action group does not run. I tried running the macro and pressing ⌘ at the same time, but it simply causes the macro to cancel).

Minor points about a brilliant piece of work. Thank you VERY much !

image

1 Like

Hi, @ronald. Thanks for the feedback. I'm going to send you a PM with an updated version for you to test.

1 Like

fantastic ! thank you very much

Hello Jim, you use the syntax cre: mod:1 wk . I thought that the syntax would be cre:1 wk mod: 1 wk
thank you

Where did I do that?

Were you referring to the name of a Smart Group or the Search Strings within it?

The name can be anything; the Search Strings within a Smart Group, however, must follow: Search Strings

1 Like

I now understand ! thank you

1 Like

just an idea based on an experience from last night in which I used cron to backup instead of doing it manually.

The idea is to display at the end of the backup a notification or text display window to confirm that the backup was done and listing the full path of all zip files created.

Otherwise, every morning (like me this morning) the user has to check the backup(s) of the night before. This is necessary. in my case, the backup had failed because of a mistake I made in the cron. My point is that it's tedious to have to check every morning.

thank you

Hi, @ronald. Thanks for the feedback and suggestions.

I’ve been working on an enhanced version of the macro that should address this issue and others.

Right now I have some other priorities and haven’t had time to finish the revisions and test the changes. I hope to have an update later this week.

1 Like

great ! thanks very much. Please take your time !