Copy to clipboard as JPEG image

I’m attempting to follow this advice on SO and it isn’t working: macos - Set clipboard to image - pbcopy - Stack Overflow

osascript -e 'set the clipboard to (read (POSIX file "/Users/mark/Desktop/a.jpg") as JPEG picture)'

I’m testing that line above in Terminal. I’m changing the path to a jpg on my own system. But it isn’t working. The clipboard is coming in as PNG.

Ultimately, what I’m trying to do is write an Alfred workflow to take a screenshot as a jpeg, save it to a screenshot folder as a jpg, and then automatically copy it as a jpeg to my clipboard for pasting in another location, such as a document, Scrivener, Obsidian, forum, etc.

Even if I change the MacOS screenshot format to jpg, builtin screenshots still come in as PNG to the clipboard!
defaults write com.apple.screencapture type jpg

My example script in Alfred (everything works except the clipboard is still PNG):

CURDATE=`date '+%F_%I-%M-%S'`
IMGPATH="/Users/chris/screenshots/screenshot_"$CURDATE".jpg"
screencapture -i -t jpeg -x -r "$IMGPATH"

# This is still copying/pasting as a PNG...
osascript -e 'set the clipboard to (read (POSIX file "'"$IMGPATH"'") as JPEG picture)'
  1. I wonder why this isn’t working as expected. Monterey regression? Is there a subtle typo/bug on my part?
  2. Anyone know any alternatives I can try?

I’m pretty sure CleanShot X would do that for you out of the box.

Thanks, but I’m interested in solutions I can script and automate.


I notice when copying the file directly from Finder, it contains «class furl» and utf8

osascript -e 'clipboard info'

«class furl», 100, «class ut16», 64, «class utf8», 31, «class icns», 1149244, Unicode text, 62, string, 31, «class 8BPS», 1304244, GIF picture, 75570, «class jp2 », 113317, JPEG picture, 63958, TIFF picture, 4198020, «class PNGf», 307783, «class BMP », 4194358, «class TPIC», 800331

Maybe someone can suggest the syntax to copy the file url instead of the image? The file is already stored in my screenshots folder. I think that would work for me too.

For example:
osascript -e 'set the clipboard to (read (POSIX file "'"$IMGPATH"'") as «class furl»)'

But that doesn’t work, because it loads the entire image data into the furl.
«class furl», 47531

And as «class utf8» just copies “«class utf8»” to the clipboard.

Actually, I should have read more carefully. From that same S.O. thread, the bottom down-voted comment. It seems a bit hacky, but it works. And this seems to be the equivalent of copying the file directly from Finder, which gets the furl and pastes as the actual format of the file (in my case, jpg):

osascript -e 'tell app "Finder" to set the clipboard to ( POSIX file "<PATH_TO_IMAGE>" )'

This doesn’t work for copying images into this forum for example. But that’s ok for now. It works for pasting into documents or note-taking apps.