How to autoprocess screenshots with an optimizer such as ImageOptim and then place immediately back in pasteboard (clipboard) for paste

copy/pastescreen capture

I'm not entirely clear on how the screenshot + pasteboard handling on macOS works. For example, as a user I perceive that when I press <shift-control-cmd-4> I can select a region of my screen and capture this screenshot into the pasteboard. I then can simply <cmd-v> (paste) this into many applications. Fore example, if I paste this into most chat applications (Messages, MatterMost, Discord, etc.) it shows up as a PNG file that is then uploaded to the hosting service.

Is there a way method to capture a pasteboard image and then send this to an optimizer (something like ImageOptim that generally get's between 15-25% additional lossless compression out of most screenshots) that can then put this back into the pasteboard for pasting it on into an app for additional seamless lossless compression?

Best Answer

I don't want to take the time now to actually do it, so I'll just point you in the directions I would take. If better answers become available, we can just delete this one :-)

There are two region capturing methods native to the Mac, one saves the file (Desktop by default, but can be anywhere) and one just puts it in your clipboard (some temp file somewhere most likely). You can change the shortcuts, file type and more... some through Preferences, some (file type) through command line in Terminal.

For example, swith the file format with defaults write com.apple.screencapture type jpg...

To process a region snap and get it back into clipboard:

  1. You can do this with Alfred. You may need to save the file instead of just using the clipboard. (AUtomatically Save it to disc, process with compression of your choice (there's even imageoptim Alfred workflow) and put it back into your clipboard with some notification that it's done.) You could start with these Workflows probably and modify them...

  2. You can do the same thing with Keyboard Maestro if that's more of your jam.

  3. You may be able to do it with Automator, but I'm not sure about that.