Compress images via TinyPNG/JPEG?


I’m trying to auto-compress images via, via their API;

(One can get the API key here, takes ±20 seconds;

I’ve been successfull sending the CURL request via;

// @$KMVAR_Path takes the current selected file
curl -i --user api:{API_KEY} --data-binary @$KMVAR_Path

But not successfull with actually downloading the image.
When executing the above I get the json response similar to;


Tried saving the response and continue from there, but that seems to be a big mess.

PS. Retreiving a image can be done via;

curl --dump-header /dev/stdout --silent api:{API_KEY} --output test.png

Any thoughts?


Why don’t you use a command line utility which resides on your machine locally? Maybe Imageoptim-CLI?

TinyPNG is by far the best optimization I’ve tested. I’ve done extensive testing in the past and they came out best in regards of compressing and rarely quality loss. So that why I really like them.

Besides that I prefer to not be reliant on installing command line utility.

Hi Sormano,

Did you manage to create this macro? I am currently trying to use TinyPNG API with Keyboard Maestro.



Hi Cary,

Unfortunately not. As it wasn’t too important for me I didn’t spend hours trying to though…



Ok, I managed to create a macro:

Compress with TinyPNG.kmmacros (51.8 KB)

This macro will take a set of PNG or JPG files and compress them using the online TinyPNG service:

You need an active internet connection and an API key for this to work.

Grab your unique API key here: (the free one allows you to convert up to 500 PNG files per month) and enter it here:

The process may take some time, especially if you have selected several large image files, but you will be notified on completion.

Spot the difference:


Hi Cary

7 years later, and I found your macro and installed it and it works perfectly! I have been a regular user of TinyPNG for website work and it just made so much sense to automate the process with KBM.

It works for a Finder selection. But I have recently been using alternative Finder apps such as Forklift and Pathfinder. So the "Finder's Selection Collection" for the Execute Action does not work with these. Nor does the option to use "Running Application's Collection".

I will start investigating further, but perhaps someone has already encountered this issue and may have a solution at hand?

Thanks again.


1 Like

It's always good to jump in the deep end and give it a go yourself.
After a bit of experimentation, here is the change I finally ended up making, so that this works now in Forklift...

Hi John,

For Path Finder, please see this thread: