Jump to content

process screenshots w imageoptim


Recommended Posts

almost everytime i take a screenshot on my mac, i want to process it imageoptim. i found a bunch of workflows already (for example here and here) but none process the image automatically.

 

does anyone know of any workflows that will automatically shrink screenshots via imageoptim?  ie: take a screenshot, automatically process it via imageoptim?

 

ps - an even cooler flow would include uploading it to my dropbox and adding the link to my clipboard but that's a lower priority

Link to comment

Maybe @Mr Pennyworth could add this to his Cleanshot Workflow (if you're willing to try Cleanshot).

 

Another way to solve for this is to attach a Folder Action (unrelated to Alfred) that runs an ImageOptim CLI script any time a new image is added to your Screenshots folder, which you can set by using this command:

 

defaults write com.apple.screencapture location /path/;killall SystemUIServer

 

This blog post about @vitor's TinyPNG Workflow may also be relevant.

Edited by Chris Messina
Added TinyPNG link
Link to comment

All you have to do is use the screencapture tool which ships with macOS to take the screenshot, then compress it. It’s done in three short lines in a Run Script Action with default options:

 

readonly image="${HOME}/Desktop/$(date).png"
screencapture "${image}"
open -a 'ImageOptim' "${image}"

 

If you want the screen capture to be interactive, change the second line to screencapture -i "${image}". If you want more options, open a terminal and run man screencapture.


This method will open ImageOptim’s GUI, though. I’ve opened a pull request with one of the Workflows you linked to add support for an External Trigger. Meaning that if they merge it (or just download this version which is ready), you can replace the third line from above with:

 

osascript -e "tell application id \"com.runningwithcrayons.Alfred\" to run trigger \"optmize_image\" in workflow \"ws.willner.alfred.imageoptim\" with argument \"${image}\""

 

And it will do what you want.


To trigger the code, use whatever you want. You’ll likely want a Hotkey Trigger. If you want to use the default screenshooting shortcuts, you’ll have to disable them from macOS in System Preferences → Keyboard → Shortcuts → Screenshots.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...