Trying to save image to clipboard

I’m trying to write a script that will save the image in the clipboard to a file on the Desktop without having to paste it into a graphics application first. I’ve got this so far:

set myDestination to “User Files:Users:pat:Desktop:”
set theFile to ((temp as text) & “imageSizeTemp”)
set theClip to the clipboard

set f to open for access file newFile with write permission
try
set eof of f to 0
end try
write clip to f
close access f

The file, however, is unreadable even if I append the correct extension. I think this is because clipboards are stored like records and so there is extra data in there, but I can’t see in the file because it’s all binary.

Does anyone have any idea how to do this, even through the terminal?

Thx, Pat
[/b]

Hi,

If it’s just picture data on the clipboard, then it’s not a record. However, when you get the clipboard it is a list. I haven’t tried every scenario here in OSX but have succeeded in creating a file (picture) from the clipboard data. It’s a little different from pre OSX and needs some experimenting. Maybe somebody already has the answers.

What I’m thinking about now is how to determine the format (file type) of the picture data. I’m sure it can be done.

gl,

If I run this code, GraphicConverter recognizes/displays the output as an image. Preview does not and it won’t even open a window for the file.

set f_path to ((path to desktop as Unicode text) & "Clipboard Image.jpg")

set clip to the clipboard
try
	set f to open for access file f_path with write permission
	try
		set eof of f to 0
	end try
	write clip's item 1 to f
	close access f
on error
	try
		close access f
	end try
end try

– Rob