Skip to content Skip to sidebar Skip to footer

Need A Way To Load Image File Into Mac Clipboard Using Python

I have a Python program that I'm porting to Mac. I need to load a saved image file into the clipboard so that it can be pasted into a document using cmd + v. This was the closes

Solution 1:

You have likely got a linefeed at the end of your string inpath, so try:

inpath = line[2].strip('\n')

Then you want:

subprocess.run(["osascript", "-e", "set the clipboard to (read (POSIX file \""+ inpath  +"/tc.jpg\") as JPEG picture)" ])

Solution 2:

Mac has a command line utility for this:

pbcopy

ONLY reads std in. E.g.

cat image.jpg | pbcopy

Post a Comment for "Need A Way To Load Image File Into Mac Clipboard Using Python"