Last active
October 12, 2020 12:34
-
-
Save ffeu/ebbade2e2e91a9a8576bd7ff06b9367a to your computer and use it in GitHub Desktop.
Gist to document a way to add a MacOS Automator Quick Action which automatically extracts the images inside a ZIP file. This is useful when you pick and download a few images taken from iPhone from Google Photos, and instead of an Image you get a ZIP file. This will extract the images inside the ZIP file and delete the original file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for fullpath in "$@" | |
do | |
dir="$(/usr/bin/dirname $fullpath)" | |
filename="${fullpath##*/}" # Strip longest match of */ from start | |
base="${filename%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end | |
ext="${filename:${#base} + 1}" # Substring from len of base thru end | |
if [[ -z "$base" && -n "$ext" ]]; then # If we have an extension and no base, it's really the base | |
base=".$ext" | |
ext="" | |
fi | |
# echo -e "$fullpath:\n\tdir = \"$dir\"\n\tbase = \"$base\"\n\text = \"$ext\"" | |
/usr/bin/unzip -o -qq "$fullpath" -d "$dir/$base" | |
for temp_file in $dir/$base/*; do | |
# echo "temp_file = $temp_file" | |
temp_filename="${temp_file##*/}" | |
temp_dir="$(/usr/bin/dirname $temp_file)" | |
temp_base="${temp_filename%.[^.]*}" | |
temp_ext="${temp_filename:${#temp_base} + 1}" | |
if [[ -z "$temp_base" && -n "$temp_ext" ]]; then | |
temp_base=".$temp_ext" | |
temp_ext="" | |
fi | |
# echo "ext = $temp_ext" | |
if [[ "$temp_ext" == 'heic' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.heic" | |
fi | |
if [[ "$temp_ext" == 'HEIC' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.heic" | |
fi | |
if [[ "$temp_ext" == 'jpeg' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.jpg" | |
fi | |
if [[ "$temp_ext" == 'JPEG' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.jpg" | |
fi | |
if [[ "$temp_ext" == 'jpg' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.jpg" | |
fi | |
if [[ "$temp_ext" == 'JPG' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.jpg" | |
fi | |
if [[ "$temp_ext" == 'png' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.png" | |
fi | |
if [[ "$temp_ext" == 'PNG' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.png" | |
fi | |
if [[ "$temp_ext" == 'gif' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.gif" | |
fi | |
if [[ "$temp_ext" == 'GIF' ]]; then | |
/bin/mv "$temp_file" "$dir/$base.gif" | |
fi | |
done | |
/bin/rm -rf "$dir/$base" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create the Quick Action in Automator.
Change
Workflow receives current
tofiles or folders
Change
Shell
to/bin/zsh
Change
Pass Input
toas arguments
Use the script in the Gist to populate the Run Shell Script action.