shou2017.com
JP

Automatically Compress and Save Images to a Desired Location on Mac

Mon Apr 23, 2018
Sat Aug 10, 2024

Previously, I used an app to compress PNG images for this blog. However, I found it tedious to manually specify the save location after compression. To streamline this process, I decided to automate it. Apps typically allow only one save location.

The tools used are:

Installing pngquant

To compress PNG images, we use pngquant.

Install it using Homebrew:

$ brew install pngquant

If you’re unfamiliar with installing Homebrew, refer to this guide.

Setting Up Automator to Automatically Compress Images in a Specified Folder

Select the Automator service.

Automatically Compress and Save Images to a Desired Location on Mac

Set “Service receives selected” to “image files” and “in” to “any application.”

Automatically Compress and Save Images to a Desired Location on Mac

Choose “Run Shell Script,” set the shell to /bin/bash, and pass input as “arguments.”

Use the following command options:

/usr/local/bin/pngquant --ext .png --force "$@"

Automatically Compress and Save Images to a Desired Location on Mac

This completes the image compression setup. Additionally, configure notifications by searching for “Show Notification” in the search box. This will notify you when the image is compressed.

Save the setup.

Configuring Folder Actions

The Automator file saved earlier doesn’t allow you to choose a save location. By default, it’s saved in the Library’s Services. You can access the Library by holding the Option key while selecting “Go” in Finder.

Automatically Compress and Save Images to a Desired Location on Mac

To set up folder actions, move the Automator service created earlier to Folder Actions in the Library’s Workflows.

Automatically Compress and Save Images to a Desired Location on Mac

Automatically Compress and Save Images to a Desired Location on Mac

Right-click the folder, select “Services,” and choose “Folder Actions Setup…” Select the Automator service created earlier.

Automatically Compress and Save Images to a Desired Location on Mac

After setup, it should look like this:

Automatically Compress and Save Images to a Desired Location on Mac

Test by moving an image to the folder. It works perfectly.

Automatically Compress and Save Images to a Desired Location on Mac

Creating Aliases to Simplify the Compression and Save Process

Create aliases by right-clicking the folder. Note that folder actions cannot be set from alias folders, so set them from the original folder.

I have separate folders for blog images and thumbnails, configured as follows:

Automatically Compress and Save Images to a Desired Location on Mac

Automatically Compress and Save Images to a Desired Location on Mac

Tags
Apple
See Also