MACRO: @ZIP T -- Zip Folder (& all Sub-Folders) & Move to TRASH
VER: 2.0 2016-12-22 ~~~
DOWNLOAD:
@ZIP T -- Zip Folder (& all Sub-Folders) & Move to TRASH.kmmacros (17 KB)
Please post your comments and feedback.
If you do find an issue, and/or have a suggestion for improvement, please feel free to post below.
Continuing the discussion from Creating a zip file and recursing through subfolders:
Building on the great macro/script provided by @rjames86 in the above post, I have built (after many iterations with his advice), a macro I now think worthy of general consumption.
The key points of this macro are:
- It creates a zip file of the source folder, and all of its files and sub-folders.
- The name of the zip file is the name of the source folder.
- It retains all of the folder structure.
- It does a zip integrity check to ensure that the zip was successful.
- Only then, if the zip was successful, does it move the source Folder to the Mac Trash.
Example Results
ReleaseNotes
HOW TO USE:
- Select one or more FOLDERs in the Finder
- Each Folder wll be put in a separate Zip file
- Trigger this Macro
MACRO SETUP
- Move Macro to Group which limits activation to Finder
- Assign a Trigger of your choice (default is Status Menu)
KEY POINTS
- It creates a zip file of the source folder, and all of its files and sub-folders.
- The name of the zip file is the name of the source folder.
- It retains all of the folder structure.
- It does a zip integrity check to ensure that the zip was successful.
- Only then, if the zip was successful, does it move the source Folder to the Mac Trash.
RESULTS:
- Each Folder will be put in a separate Zip file.
- IF the Zip file was created successfully, with integrity, then the source Folder was moved to the Mac Trash
- A Report will be displayed providing details.
Author: @rjames86 -- Original Macro/Script as shown below
@JMichaelTX -- this macro based on the one by @rjames86
WARNING!
The Folder selected in the Finder will be MOVED TO TRASH, IF the Zip was successful.
If the Zip File already exists, it will be OVERWRITTEN.
REFERENCE
Topic: Creating a zip file and recursing through subfolders
Forum: Keyboard Maestro Discourse, general
Post by: rjames86
Post Date: 2016-12-22
Script Lang: Bash
Post URL: Creating a zip file and recursing through subfolders
If you want to change the name of the zip file,
- just set a new variable in KM and
- then change the line to
zip -rm "$KMVAR_<thevarname>" "$BASE"
where <thevarname>
is the name of your variable
For a detailed, step-by-step description of the script, see:
The above post by rjames86
TESTING
I have tested this a fair amount using:
Keyboard Maestro 7.3.1 (7.3.1) on macOS 10.11.4
and have not found any bugs or issues.
However, if you do find an issue, and/or have a suggestion for improvement, please post below.
Bash Shell Script
SAVE_DIR=`dirname "$KMVAR_ZIP__Folder"`
BASE=`basename "$KMVAR_ZIP__Folder"`
BASE_NO_EXT=${BASE%.*}
pushd "$SAVE_DIR"
zip -rT "$BASE_NO_EXT" "$BASE"
if [[ `unzip -tq "${BASE_NO_EXT}.zip"` =~ "No errors detected" ]];
then
osascript -e 'tell application "Keyboard Maestro Engine" to setvariable "ZIP__NoErrors" to "true"';
else
osascript -e 'tell application "Keyboard Maestro Engine" to setvariable "ZIP__NoErrors" to "false"';
fi
popd