The following thread motivated me to document and share a macro that I use frequently:
In that thread, @iorek was looking for a way to watch ~/Downloads for an archive file matching a specified regular expression. With help from @kevinb, @kcwhat, @tiffle, and @Nige_S, a solution was developed that automatically extracts a matching archive and then moves the original archive to the Trash.
My use case is similar, but my workflow preferences are a little different, so I thought it would be better shared in a new thread.
In my ~/Downloads folder, I keep a subfolder named _ExtractAndTrashArchive. This combined with a macro with a Folder Trigger provides two simple workflows:
-
Extract and trash the archive: Move the archive into
_ExtractAndTrashArchive. -
Extract but keep the archive: Copy the archive into
_ExtractAndTrashArchive.
Since the process is triggered only when I intentionally move or copy an archive into that folder, newly downloaded archives are not processed automatically. I use this approach since it gives me control over which archives are processed while still automating the repetitive extraction and cleanup steps.
MACRO: Extract & Trash Archive (Watch Folder)
PURPOSE
This macro watches a folder for new archive files (zip or cpio). When one appears, it:
-
Extracts the archive's contents into the same folder
-
Moves the original archive to the Trash
SETTINGS
local_Overwrite Determines how naming collisions are handled. This value is always set by a calculation earlier in the macro:
-
1: an existing file or folder with the same name is replaced. -
0: nothing is replaced. The new item is given a numeric suffix (2,3,4, ...) instead. For example,Notes.txtbecomesNotes 2.txtif the former already exists.
NOTES
Uses ditto. unzip is a general-purpose tool that does not understand macOS-specific file metadata, such as resource forks and extended attributes. ditto, an Apple tool, preserves metadata correctly during extraction, making it the more reliable choice on macOS.
Supported extensions. ditto can extract two archive formats: PKZip (.zip) and CPIO (.cpio), including gzip-compressed CPIO (.cpgz). The macro checks for these three extensions before attempting extraction.
Extraction occurs outside the watched folder. Extracting directly into the watched folder could generate extra filesystem activity that would retrigger the watching macro during the extraction process. Performing extraction in a temporary location minimizes this; the extracted contents are moved into the watched folder, which will retrigger the macro; but the macro will only process archives.
TESTED WITH
- Keyboard Maestro 11.0.4
- Tahoe 26.5.2 (25F84)/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 - Removed the local_Extensions setting. Extensions are now hardcoded to zip, cpio, and cpgz, matching what ditto is capable of extracting.
Download: Extract & Trash Archive (Watch Folder).kmmacros (8.0 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 26.5.2 (25F84)
- Keyboard Maestro v11.0.4
MACRO: Touch _ExtractAndTrashArchive
PURPOSE
When any file is added to ~/Downloads, touch subfolder _ExtractAndTrashArchive.
The result: when ~/Downloads is sorted by Date Modified in the Finder, _ExtractAndTrashArchive appears at the top.
TESTED WITH
- Keyboard Maestro 11.0.4
- Tahoe 26.5.2 (25F84)/MacBookPro18,2
- Mojave 10.14.16/Macmini6,2
- High Sierra 10.13.6/iMac11,1445
VERSION HISTORY
1.0 - Initial version
Download: Touch _ExtractAndTrashArchive.kmmacros (5.2 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 26.5.2 (25F84)
- Keyboard Maestro v11.0.4


