copy IMAGE contents to CLIPBOARD +++ PLEASE SAVE ME!!!!!!!!!!!

Hi,
How do I copy an image contents to the clipboard using applescript?
I would like to be able to paste it, in any other application after the script!

I have tried this:

set this_file to open “path and image goes here”
set the clipboard to this_file

after running this script, I try to paste on textedit, photoshop, etc, and I GET NOTHING!!!
I need the script to be application independent, so I can just use just regular commands of MacOS X Tiger.

Please help me! I am desperade!!!

:slight_smile:
thanks

Model: mac mini
AppleScript: tiger 10.4.2
Browser: Safari 412.2
Operating System: Mac OS X (10.4)

Hi,

AppleScript as is cannot work with data of images. All it can do is pass it from one app to another or read from a picture file and pass the data to an app that can work with the data.

One thing you can do is open the file in some common app and use ui scripting to copy the image. The following uses Preview:

set this_picture to choose file
tell application “Preview”
activate
open this_picture
end tell
tell application “System Events”
tell process “Preview”
keystroke “c” using command down
end tell
end tell
tell application “Preview” to quit

gl,

Hi Kel,
T H A N K Y O U ! ! ! ! ! ! ! !
You are THE MAN!!!

What kind of books , docs, pages, can I read to become an applescript wizard like you?
I would like to learn everything, things like

keystroke “c” using command down (this line is a master piece…:slight_smile:

and events!!!

everything!
Thank you again!!!

Hi macos_boy,

Thank you.

I don’t know of any books, but here’s a link to the Apple site on ui scripting:

http://www.apple.com/applescript/uiscripting/01.html

There might be something on the subject at this site also.

Personally, I just learned from reading the AppleScriptLanguageGuide.PDF, other documents, other people, and experimenting. It gets easier when you know how to use dictionaries.

gl,

Actually, AppleScript does know about images natively. I’m not sure why, but the following script works if you want to paste into TextEdit or Preview (and I assume most applications) but, curiously, not Photoshop (at least not on my machine):

try
	set the clipboard to (read (choose file with prompt "Select an image file:" without invisibles) as TIFF picture)
end try

I tried other image classes (JPEG picture and picture) but TIFF picture seemed to work the best. I tested on JPEG and TIFF images.

Jon

Hi Jon,

as TIFF works here also. THat’s strange.

Thanks,
gl,

I tried copy image to the clipboard following the book “AppleScript A Comprehensive Guide to Scripting and Automation on Mac OS X” which shows exactly the same way posted in the messages. I copy the tiff image to the clipboard but could not paste it, it hangs, I have to use force quit to quit the process. Any idea?

I’ve often used the Scripting Addition “GraphicsImporter”
http://osaxen.com/files/graphicsimporter2.2.html

Sorry, a little correction to my previous post:
I paste copied image works fine, but if I use following script to set the copied data to a variable cause hang.

set the_clipboard_data to the clipboard

Any idea about this?

Fenton, could you please give a description how to use freeware ImageConvertor 2.2 after I download it to a folder? I see it is a .bin file.

Thanks!

xhuang

If it’s still a .bin file it means it did not expand all the way after being downloaded. I guess you should drop it on Stuffit Expander (which you probably have, or can download). It is a Scripting Addition (OSAX), which you should already have a folder for; in 2 locations:

“Macintosh HD:System:Library:ScriptingAdditions:”
“Macintosh HD:Users:your home folder:Library:ScriptingAdditions:”
(If the 2nd folder isn’t there yet, you can create it.)

Put the actual GraphicsImporter OSAX file in one of the two folders above. That’s all. Read its dictionary (drop the GI OSAX on Script Editor to quickly see). It only has 2 commands: giconvert and giget

I used it to convert an image in a FileMaker container field to a file. This is now longer really necessary in FileMaker 7, since you can use the FileMaker Export Field script step instead.

If you’re trying to set the clipboard to a file, then you’d use something like:

set the clipboard to (giconvert (choose file) type “JPEG”)

“JPEG” works fastest. If you don’t specify you get a “PICT”, which is the old standard. It will open (as PICT) .pdf and .gif, but only if you don’t specify; it errors if you do. “TIFF” works fine however.

The following will save the clipboard as a file:
set theFile to (((path to desktop) as string) & “newImage.jpg”) as file specification
set theImage to the clipboard as picture
set thePict to giconvert (theImage) type “JPEG” image theFile

I’m not an expert at this. But it has worked for me and is fairly simple to use.

Fenton,

Thanks so much! Your posts are great help!

Xhuang