I want to copy an image (PIL image) to clipboard on Mac OS
I tried dozens of different ways to do that. Most of python clipboard modules like pyclip or clipboard doesn't support images.
I found a code that does that on windows, but nothing for mac. I tried to use QT, installed it through brew, for some reason brew installed a new python 3.7.2 (I had 3.7.1) and messed up with terminal commands like python and python3. I managed to fix it, but it's very frustrating. And I couldn't get it to work anyway.
I've seen a method with win32 clipboard, but it's for windows only. I tried various different modules, but none of them accept images. I couldn't come up with a solution, so I'm here asking for help.
A little background. I'm writing an app that will save the image from the clipboard and saves it to a file. I have no problem with this, but I also want to store what I saved and later to be able to pull it back to the clipboard. Like Open Last Saved.
解决方案
This little piece of ugliness works and loads "image.jpg" onto the clipboard...
#!/usr/bin/env python3
import subprocess
subprocess.run(["osascript", "-e", 'set the clipboard to (read (POSIX file "image.jpg") as JPEG picture)'])