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.
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-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