Building an image optimizer app using macOS Shortcuts

Content editors on my team need to add images to the web often, and each image needs to be optimized. I’ve decided I want to build them a Shortcuts app that can resize and compress multiple images in one easy swoop.

Google’s Squoosh app can seemingly do this using their npx command. After uploading an image in their interface, you can adjust the resizing and compression options in the right panel. Then, Squoosh will generate the npx command with those options configured.

The command generated with these options comes out to this:

npx @squoosh/cli --resize '{"enabled":true,"width":1280,"height”:auto,”method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}'

To my knowledge, if I want to translate this operation into Shortcuts I would need a file input from the user, then run a shell script using that file input. So it looks like this:

However, I keep getting errors with every configuration I use. I can’t tell if I’m missing a step, my syntax is wrong, or there’s an error with the npx package.

Anyone have ideas for getting this to work?

1 Like

HI @joejola I can’t help you with your request but why you using 3d-party software to create shortcut when macOS “Preview” does exactly your team members need. Just teach them how to use Apple macOS if they aren’t familiar with this platform.

I am not familiar with creating shortcuts but why not to use native macOS tools (even for shortcuts)

Preview offer resizing and colorizing …

and on save offer compression and image format.

but it’s use will be strictly to macOS team members. If you need build a tool for everyone you can build node web app with help of Jimp and Multer etc.Using Multer to load img to memory than process it with Jimp and spilt out optimized image.

It will be an overkill as you have native macOS tools but you can have fun to build it and host on eg. Vercel :wink: