Quickly Compress Images with Automator (mac)
- Fire up Automator (CMD + SPACE, “automator”, ENTER)
- File > New, Select “Quick Action”.
- In the search field search for “run shell script”, drag the item to the right area.
- Setup like this:
- “Workflow receives current” = “image files”
- “in” = “finder”
- “Shell” = “/bin/bash/”
- “Pass input” = “as arguments”
- Paste the following code into the text field below (delete the example code before)
for f in "$@"
do
echo $f | while IFS= read file
do
filename=$(basename $file)
ext=$(echo ${filename##*.} | tr "[:upper:]" "[:lower:]")
if [ -f $file ]
then
if ( [ $ext == "png" ] || [ $ext == "jpg" ] || [ $ext == "jpeg" ] )
then
JSON=curl -i --user api:APIKEY --data-binary @$file https://api.tinypng.com/shrink 2>/dev/null
URL=${JSON/*url\":\"/}
URL=${URL/\"*/}
curl $URL>${file} 2>/dev/null
fi
fi
done
done
afplay /System/Library/Sounds/Submarine.aiff
- Request a API Key from TinyPNG
- Click the Link in the Email TinyPNG sends you.
- Copy the API Key and replace it in the code fragment where it states APIKEY.
- File > Save!
- Name the service how you want it to show up in the context menu. (Example: Compress Images).
- Done! Right click on an image file in the finder an hit “Compress Images” to let the magic happen!