rayps Posted February 27, 2021 Share Posted February 27, 2021 Hello everyone. I'm making a workflow to convert the copied PNG then paste it as JPG. The PNG is mostly just screenshot taken with ⌘⇧⌃4 or copied through the "Copy Image" in the context menu of Chrome/Safari. My goal is after copied/captured a PNG image, run the workflow in Alfred, then paste it somewhere as JPG, more excatly not pasting it in Finder but in some other software, document editing or Discord ,etc. I was able to read the clipboard image with {clipboard:0}, but it seems like only getting a text description as in Alfred's clipboard history. And I also know that I can set clipboard content with "Outputs > Copy to Clipboard", but only the content types of text or rich text are allowed. If anyone can give me an idea I will be appreciated. Link to comment
deanishe Posted February 27, 2021 Share Posted February 27, 2021 1 hour ago, rayps said: I was able to read the clipboard image with {clipboard:0} That only works with text. You can't pass around binary image data in a workflow. If you want to manipulate images on the clipboard, you'll have to do it via Apple's APIs. Link to comment
rayps Posted February 28, 2021 Author Share Posted February 28, 2021 Thank you! I managed to get it work today. I'll put the solution here in case Google index this post. https://gist.github.com/RayPS/5f8c31de2a4ded2f0e947996c30ab1fe Link to comment
deanishe Posted February 28, 2021 Share Posted February 28, 2021 Glad you figured it out. Is that script right? You're putting the JPEG data on the clipboard as TIFF data. Link to comment
rayps Posted March 1, 2021 Author Share Posted March 1, 2021 Yes, somehow it just worked as I expected. It's a little bit confused at the first moment, it's seems like that's how macOS store bitmap data in clipboard. Because there's no JPEG type in NSPasteboard.PasteboardType Link to comment
deanishe Posted March 1, 2021 Share Posted March 1, 2021 2 hours ago, rayps said: it's seems like that's how macOS store bitmap data in clipboard. TIFF's a complicated format. I'm sure it supports JPEG compression, amongst other things. 2 hours ago, rayps said: there's no JPEG type in NSPasteboard.PasteboardType You should be able to use the string public.jpeg Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now