MACRO: Export and Zip Group Macros, v6.0

Prior to Version 6.0, this macro was named Zip Smart Group(s). That macro should be deleted before installing this version. Existing calling macros can be retained and, if older versions of this macro are first deleted, should automatically refer to this macro in the Execute a Macro action.

DESCRIPTION

This macro provides a quick and simple method to export the macros listed in any Smart Group or Macro Group. All group macros exported will be optionally zipped into a single archive file. The export folder and archive name include:

  • Date & time
  • {Smart Group} or [Macro Group] name
  • macro count

For example, for Smart Group 4-Cre Mod 7d:

2025-02-11 1941_25 {4-Cre Mod 7d} (27 macros).zip

And for Macro Group :Demo._𝗷𝗶𝗺𝘀:

2025-02-11 1942_06 [:Demo._𝗷𝗶𝗺𝘀] (26 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 as Folder... is that it maintains the Macro Group hierarchy when the macros are exported. Thus, even if a Smart Group is selected, each macro exported is within a subfolder named to match the parent Macro Group.


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

For example, one 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 all macros created or modified within the last 4 hours, would be saved within a single zip file.

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


ADDITIONAL FEATURES

Initial state restored. When the macro is triggered, it saves the state of the Keyboard Maestro Editor (including macro group and macro selections). When the macro completes, the state is restored.

Export names adjusted as needed. The Keyboard Maestro Export as Folder... command automatically replaces colons ( : ) and slashes ( / ) with dashes ( - ) in macro groups and macros to maintain compatibility with macOS file names. In addition, with this macro, if the first character is dot ( . ) or dash ( - ), it is replaced with an underscore ( _ ). (If the first character was a dot, but not changed, the file would be invisible in the Finder; if the first character was a dash, but not changed, shell command syntax would be more complicated.) If local_DropboxSafe = 1, then additional replacements are made. See SETTINGS below.

Export confirmation. The Keyboard Maestro Search field is cleared before the macros are exported. When the export completes, before the export folder is zipped, the exported macros are counted and compared to the number of macros that are in the selected Smart Group. If counts do not match, a notification is generated and the information is also added to the summary dialog.

A calling macro can customize behavior. If the macro is triggered from another macro, one or more group Name(s) and/or UUID(s) can be optionally supplied and the selection list will be bypassed. In addition, the calling macro can override the default settings with respect to feedback and zip creation. For more information, see USING ANOTHER MACRO TO TRIGGER.


SETTINGS

> local_BackupRootPath
The exported folder will be be saved in this folder path. If they do not exist, the subfolders in the path (below home: ~) will be created by the macro. When this macro is downloaded, this value will be specified:

~/Documents/Automation/_Keyboard Maestro/Exports

If this path is not specified, the exported folders will be written to: ~/Downloads

> local_IncludeSmartGroups : 0|1; default 1 : When triggered directly, this variable is used to determine if the Smart Groups are displayed for export. When 1, local_SmartGroupPatterns can be optionally used to display a subset of Smart Groups.

> local_IncludeMacroGroups : 0|1; default 1 : When triggered directly, this variable is used to determine if the Macro Groups are displayed for export. When 1, local_MacroGroupPatterns can be optionally used to display a subset of Macro Groups.

> local_SmartGroupPatterns
When triggered directly, this variable can be optionally used to limit the Smart Groups displayed for export. 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 (assuming local_IncludeSmartGroups = 1).

> local_MacroGroupPatterns
When triggered directly, this variable can be optionally used to limit the Macro Groups displayed for export. 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 Macro Groups (assuming local_IncludeSmartGroups = 1).

> local_DefaultFeedback : [dialog] | [reveal] | [none]; default [dialog] : When this macro is triggered directly, this variable is used to specify the action that follows the creation of each export folder or zip file.

[dialog] : A dialog will appear after the group is exported. If multiple groups are specified, then the final dialog will also include a Reveal button.

[reveal] : No dialogs will appear, however, the exported folder (or zip file created) will be revealed in the Finder. If multiple groups are specified, then the last created folder or zip file will be revealed.

[none] : Aside from the normal Export to Folder... notification, there will be no feedback.

In all cases, when the macro completes, the Keyboard Maestro Editor will be returned to its initial state including the selections within the Groups and Macros columns.

> local_DefaultFeedbackWhenCalled : [dialog] | [reveal] | [none]; default [reveal] : When this macro is triggered from another macro or via AppleScript, this variable is used to specify the action that follows the creation of each export folder or zip file.

[dialog] : A dialog will appear after the group is exported. If multiple groups are specified, then the final dialog will also include a Reveal button.

[reveal] : No dialogs will appear, however, the exported folder (or zip file created) will be revealed in the Finder. If multiple groups are specified, then the last created folder or zip file will be revealed.

[none] : Aside from the normal Export to Folder... notification, there will be no feedback.

In all cases, when the macro completes, the Keyboard Maestro Editor will be returned to its initial state including the selections within the Groups and Macros columns.

> local_DropboxSafe : 0|1; default 0 : In exported macro groups and macros, leading dots ( . ), leading dashes ( - ), leading spaces, and problematic characters for Dropbox ( / \ < > : " | ?, emojis, and other non-ascii characters) are replaced with underscores ( _ ). In addition, trailing dots ( . ) and spaces are removed.

> local_ZipExportFolder : 0|1; default 1: Zip the exported folder; otherwise leave it uncompressed.


USING ANOTHER MACRO TO TRIGGER

This macro can be triggered using the Execute a Macro action in another macro; the Smart Group(s) and/or Macro Groups are specified using the With Parameter, one Group Name or Group UUID per line. In this mode, the group Prompt With List will not be displayed. Since the settings local_IncludeSmartGroups, local_IncludeMacroGroups, local_SmartGroupPatterns, and local_MacroGroupPatterns do not apply in this mode, the macros in any configured Smart Group or Macro Group can be exported and zipped.

The first line of With Parameter can be optionally used to override two macro settings:

  • local_DefaultFeedbackWhenCalled : [dialog], [reveal], or [none]

  • local_ZipExportFolder : [zip=0], [zip], or [zip=1] (the last two being equivalent)

If the With Parameter only includes these optional parameter(s) (i.e., no group information supplied), the overrides will apply, but the normal group Prompt With List will appear.

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 exporting (but not zipping) one Smart Groups and one Macro Group:

-- Export and Zip Group Macros

property theP : "[dialog] [zip=0]
4-Cre Mod 7d
AF669DED-52E9-4784-A61F-DB98167ED0DA"

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 and Macro Group UUID are used. (See property theP.)


OTHER BACKUP MACROS AVAILABLE IN THE FORUM

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.


TESTED WITH

• Keyboard Maestro 11.0.3
• Sequoia 15.3 (24D60)/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.

4.0
a) Moved the macro to a group that can be run regardless of the running state of the Keyboard Maestro Editor. When the macro completes, the Keyboard Maestro Editor will be returned to its initial state including the selections within the Groups and Macros columns.

b) After the macros are exported and before they are zipped into an archive, macro groups and macro names are changed by substituting any leading dots (.) to a dash (-). This change makes the folders/files visible in the Finder.

c) Added setting local_DropboxSafe. If 1, the zip file name and exported macro groups and macros will be renamed to avoid characters that are problematic for Dropbox.

d) If the macro is triggered directly, multiple Smart Groups can be selected and a dialog will appear for each Smart Group; the last dialog will include a Reveal button. If selected, the last zip file created will be revealed in the Finder. In contrast, if the macro is triggered from another macro or via AppleScript, by default no dialogs will appear and the zip file will be revealed.

e) Added setting local_DefaultFeedbackWhenCalled with options of [dialog], [reveal], or [none].

f) As with previous versions of this macro, if triggered from another macro or via AppleScript, one or more Smart Group names and/or UUID's can be specified using the With Parameter (one per line). With this macro update, the first line of With Parameter can optionally be [dialog], [reveal], or [none] to specify the post-zip feedback. If not included, the value of local_DefaultFeedbackWhenCalled will be used.

5.0

a) When local_DropboxSafe = 1, the macro now also replaces emoji characters, and other non-ascii characters, with underscores ( _ ). Therefore even if the Smart Group, Macro Group, and/or Macro Name contains non-ascii characters, the archive and included folders and files will be Dropbox compatible. Note that there is one minor anomaly with emoji transformation: if the macro group or macro name includes consecutive emoji characters, the transformation will be to one underscore, not one for each emoji.

b) Added setting local_DefaultFeedback with options of [dialog], [reveal], or [none]. The default is [dialog]. This setting is used when the macro is triggered directly.

c) The Keyboard Maestro Search field is now cleared before the macros are exported. When the export completes, before the export folder is zipped, the exported macros are counted and compared to the number of macros that are in the selected Smart Group. If counts do not match, a notification is generated and the information is also added to the summary dialog.

d) The folder enclosed in the zip archive now includes the name of the Smart Group. For example, with the zip file 2025-02-02 1514_22 [4-Cre Mod 7d] (51 macros), the archived folder would be 2025-02-02 1514_22 [4-Cre Mod 7d].

e) The JXA that collects the Smart Group information for the first Prompt With List is more memory efficient. The macro should now work properly even if the library contains hundreds of Smart Groups.

f) The JXA and shell scripts are now set to capture and report any errors that might occur. Also, the progress bars will be dismissed even if these actions were to fail.

6.0

a) Changed the name from Zip Smart Group(s) to Export and Zip Group Macros.

b) Added capability to back up Macro Groups in addition to Smart Groups.

c) When called from another macro, the first line of the With Parameter can now include two optional sets of parameters that override the macro settings local_DefaultFeedbackWhenCalled and local_ZipExportFolder, respectively. The two set are:
set 1: [dialog], [reveal], [none]
set 2: [zip=0], [zip], [zip=1]; the last two being equivalent

If the With Parameter only includes these optional parameter(s) (i.e., no group information supplied), the overrides will apply, but the normal group Prompt With List will appear.

d) Changed SETTING local_BackupRootPath to local_ExportRootPath.

e) Added SETTINGS: local_IncludeSmartGroups, local_IncludeMacroGroups, local_MacroGroupPatterns, and ZipExportFolder.

f) The export folder now reflects the number of enclosed macros. For example: 2025-02-11 1807_02 {Note-sauer} (158 macros). Smart Groups are enclosed in braces { } whereas Macro Groups are enclosed in brackets [ ].

g) When selecting the group, added check that View > Select Groups Column is enabled. Since Failure Aborts Macro was disabled, no real functional change other than avoiding unnecessary messages in the Engine.log.

h) When displaying Smart Groups for selection, Search Strings are truncated to 70 characters.

i) Added this dialog: ERROR: The Keyboard Maestro menu item 𝗙𝗶𝗹𝗲 > 𝗘𝘅𝗽𝗼𝗿𝘁 > 𝗘𝘅𝗽𝗼𝗿𝘁 𝗮𝘀 𝗙𝗼𝗹𝗱𝗲𝗿… is not enabled.

j) In shell scripts, added: export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; export LANGUAGE=en_US.UTF-8

k) In the final shell script, changed zip to ditto since the latter is a more unicode-friendly command.


LISTS AND DIALOGS

If the macro is triggered directly, a Prompt With List like the following will appear. (By default, all Smart Groups and Macro Groups are listed. The list can be limited using an optional macro setting.) One or more (with ⇧+click or ⌘+click) groups can be selected.


By default, a dialog will appear for each group exported and zipped.


The last dialog will include and option to reveal the zip file.


If the macro is triggered from another macro using the Execute a Macro action and one or more Smart Groups and/or Macro Groups are specified (by Name or UUID), the above Prompt With List is skipped and the exports immediately commence.

Keyboard Maestro Export

As depicted above, the first line of With Parameter can be used to override two of the macro settings: local_DefaultFeedbackWhenCalled and local_ZipExportFolder


DOWNLOADS

PRIMARY MACRO

Prior to Version 6.0, this macro was named Zip Smart Group(s). That macro should be deleted before installing this version. Prior calling macros can be retained and, if older versions of this macro are first deleted, should automatically refer to this macro in the Execute a Macro action.

Download: Export and Zip Group Macros.kmmacros (216 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 (24D60)
  • Keyboard Maestro v11.0.3

EXAMPLE CALLING MACRO

Download: 𝘊𝘢𝘭𝘭 Export and Zip Group Macros.kmmacros (11 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 !

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

  • Moved the macro to a group that can be run regardless of the running state of the Keyboard Maestro Editor. When the macro completes, the Keyboard Maestro Editor will be returned to its initial state including the selections within the Groups and Macros columns.

  • After the macros are exported and before they are zipped into an archive, macro groups and macro names are changed by substituting any leading dots (.) to a dash (-). This change makes the folders/files visible in the Finder.

  • Added setting local_DropboxSafe. If 1, the zip file name and exported macro groups and macros will be renamed to avoid characters that are problematic for Dropbox.

  • If the macro is triggered directly, multiple Smart Groups can be selected and a dialog will appear for each Smart Group; the last dialog will include a Reveal button. If selected, the last zip file created will be revealed in the Finder. In contrast, if the macro is triggered from another macro or via AppleScript, by default no dialogs will appear and the zip file will be revealed.

  • Added setting local_DefaultFeedbackWhenCalled with options of [dialog], [reveal], or [none].

  • As with previous versions of this macro, if triggered from another macro or via AppleScript, one or more Smart Group names and/or UUID's can be specified using the With Parameter (one per line). With this macro update, the first line of With Parameter can optionally be [dialog], [reveal], or [none] to specify the post-zip feedback. If not included, the value of local_DefaultFeedbackWhenCalled will be used.

1 Like

Hi, @ronald. See Version 4.0.

If you run Zip Smart Group(s) from another macro and specify the Smart Group(s) (by Name or UUID, one per line), the main Prompt With List and dialogs will not appear (assuming you use the default Zip Smart Group(s) settings). Instead, the last zip file will be revealed (i.e., selected) in the Finder.

If you sort the enclosing folder by date, you will be able to quickly confirm that the other zips were created.

1 Like

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

  • When local_DropboxSafe = 1, the macro now also replaces emoji characters, and other non-ascii characters, with underscores ( _ ). Therefore even if the Smart Group, Macro Group, and/or Macro Name contains non-ascii characters, the archive and included folders and files will be Dropbox compatible. Note that there is one minor anomaly with emoji transformation: if the macro group or macro name includes consecutive emoji characters, the transformation will be to one underscore, not one for each emoji.

  • Added setting local_DefaultFeedback with options of [dialog], [reveal], or [none]. The default is [dialog]. This setting is used when the macro is triggered directly.

  • The Keyboard Maestro Search field is now cleared (using a method contributed by @Nige_S) before the macros are exported. When the export completes, before the export folder is zipped, the exported macros are counted and compared to the number of macros that are in the selected Smart Group. If counts do not match, a notification is generated and the information is also added to the summary dialog.

  • The folder enclosed in the zip archive now includes the name of the Smart Group. For example, with the zip file 2025-02-02 1514_22 [4-Cre Mod 7d] (51 macros), the archived folder would be 2025-02-02 1514_22 [4-Cre Mod 7d].

  • The JXA that collects the Smart Group information for the first Prompt With List is more memory efficient. The macro should now work properly even if the library contains hundreds of Smart Groups.

  • The JXA and shell scripts are now set to capture and report any errors that might occur. Also, the progress bars will be dismissed even if these actions were to fail.


I'd like to acknowledge @ronald: he suggested some of the above enhancements and he tested several drafts before this release.

1 Like

great. fantastic macro and thank you for mentioning me which was not necessary.

1 Like

when you have a minute, please see my post How to design a macro to ... cleanse all macros of Dropbox and Mac OS forbidden characters? - Questions & Suggestions - Keyboard Maestro Discourse

1 Like

I've updated the OP with Version 6.0 of Export and Zip Group Macros:

  • Changed the name from Zip Smart Group(s) to Export and Zip Group Macros.

  • Added capability to back up Macro Groups in addition to Smart Groups.

  • When called from another macro, the first line of the With Parameter can now include two optional sets of parameters that override the macro settings local_DefaultFeedbackWhenCalled and local_ZipExportFolder, respectively. The two set are:
    set 1: [dialog], [reveal], [none]
    set 2: [zip=0], [zip], [zip=1]; the last two being equivalent

    If the With Parameter only includes these optional parameter(s) (i.e., no group information supplied), the overrides will apply, but the normal group Prompt With List will appear.

  • Changed SETTING local_BackupRootPath to local_ExportRootPath.

  • Added SETTINGS: local_IncludeSmartGroups, local_IncludeMacroGroups, local_MacroGroupPatterns, and ZipExportFolder.

  • The export folder now reflects the number of enclosed macros. For example: 2025-02-11 1807_02 {Note-sauer} (158 macros). Smart Groups are enclosed in braces { } whereas Macro Groups are enclosed in brackets [ ].

  • When selecting the group, added check that View > Select Groups Column is enabled. Since Failure Aborts Macro was disabled, no real functional change other than avoiding unnecessary messages in the Engine.log.

  • When displaying Smart Groups for selection, Search Strings are truncated to 70 characters.

  • Added this dialog: ERROR: The Keyboard Maestro menu item 𝗙𝗶𝗹𝗲 > 𝗘𝘅𝗽𝗼𝗿𝘁 > 𝗘𝘅𝗽𝗼𝗿𝘁 𝗮𝘀 𝗙𝗼𝗹𝗱𝗲𝗿… is not enabled.

  • In shell scripts, added: export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; export LANGUAGE=en_US.UTF-8

  • In the final shell script, changed zip to ditto since the latter is a more unicode-friendly command.

1 Like