Read image from file and put on clipboard

Hello,

I’m frustratedly trying to read an image file and put it on the clipboard. I’ve searched MacScripter up and down and none of the solutions are working. Essentially this should be enough:

set the clipboard to (read theFile)

But it’s not. What I found, many people recommend to specify the picture type like so:

set the clipboard to (read alias (theFile as «class PNGf»))
set the clipboard to (read file (theFile as «class PNGf»))

Before I try my luck with JPG and other image types I want to get this working with PNG files first.

Thanks for your help.

Hello.

The «class TIFF» should work in most cases, if it doesnt, then just try «class PICT». (You’ll see below that AppleScript has expanded the class names, so you should be able to write the readable name straight out as well.

try
	tell application "Finder" to set theFile to item 1 of (get selection)
	set the clipboard to (read (theFile as alias) as TIFF picture)
on error
	display dialog "Nothing selected" buttons {"Cancel"} default button "Cancel"
end try

Here is a a fair list of AppleScript constants.

Thank you very much. The code does indeed work. I did not try TIFF picture, but it makes sense.

FYI, I’m pretty sure PICT is no longer supported on 64-bit systems.