I am needing to copy an image off a webpage into the clipboard from Safari. I can find the image number using java, but can’t figure out how to tell Safari to copy the image into the clipboard.
any suggestions?
Thanks
I am needing to copy an image off a webpage into the clipboard from Safari. I can find the image number using java, but can’t figure out how to tell Safari to copy the image into the clipboard.
any suggestions?
Thanks
This works fine here:
set the clipboard to (read alias "path:to:file.jpg" as TIFF picture)
This works with a test jpg and gif files I tried, and using Preview to create a new image from clipboard. Seems it doesn’t work, though, with other apps, which seems to be expecting PICT data… If you can stick with this method, use it. Otherwise, I think you should use a third-party app to open the image and copy the data to the clipboard. Or perhaps there is some kind of obj-c method in the Webkit framework, accessible from a Studio app.
This is my final solution to the problem
set StartUpDiskPath to the path to the startup disk as text
set pictureFile to StartUpDiskPath & "picture.jpg"
tell application "Safari" to do JavaScript "document.images[14].src" in document 1
set PictAddress to result as text
set x to the offset of ("http:") in PictAddress
set CurlAddress to text (x) thru (count PictAddress) of PictAddress
do shell script "curl " & CurlAddress & " -o " & "picture.jpg"
(* If the picture type is GIF then convert it to JPG *)
if (the offset of (".gif") in CurlAddress) is not equal to 0 then
tell application "Image Events"
launch
set img to open pictureFile
save img as JPEG in file pictureFile with icon
close pictureFile
end tell
end if
Oh yeah, I found a way to do what I needed without using the clipboard.
Browser: Safari 416.12
Operating System: Mac OS X (10.4)