been trying to get this to work all day long and failure.
One funny thing I found along the way was Tim B’s answer to the same question here:
http://lists.apple.com/archives/applescript-studio/2003/Aug/msg00155.html
In which he claims that it’s in the AS Studio Examples:
/Developer/Examples/AppleScript Studio/Image
But it’s not there (at least in my backup of that file). They only implement dropping files, not images.
Here’s what I wrote to the AS Studio mailing list just now:
I’ve spent the day to no avail trying to drop an image onto an image view –
NOT a file (which I can pull off just fine) but an image object say from
Safari. The old AS Studio example (suspiciously?) only showed the file
example.
Basically it appears to recognize the “image” preferred type. But when I do
this:
set theImage to contents of pasteboard of dragInfo
It appears to silently fail, not just get a missing value but “undefining”
the defined missing value, causing the script to choke when checking whether
theImage = missing value, with a “variable is undefined” error.
I can find no working example of this. Maybe it’s just 10.6?
(and yes, all types are registered in awake from nib… I’ve tried both
with and without connected “prepare drop” and “conclude drop” handlers.)
If anyone has seen a solution that works, please let me know!
on drop theObject drag info dragInfo
set theImage to missing value
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
[...]
else if "image" is in dataTypes then
set preferred type of pasteboard of dragInfo to "image"
try
set theImage to contents of pasteboard of dragInfo
try
set a to theImage
on error myerr
-- ERROR HERE with "variable theImage is not defined"
end try
on error myerr
-- NO ERROR HERE
end try
else if "pict image" is in dataTypes then
[...]
end if
try
if theImage is not missing value then
[...]
end if
on error
-- ERROR here, same as above, variable theImage is not defined
end try
End if
Here my actual logged data types
dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwuApp
le files promise pasteboard
typepublic.tiffimagedyn.ah62d4rv4gu8zs3pcnzme2641rf4guzdmsv0gn64uqm10c6xenv6
1a3kWebURLsWithTitlesPboardTypedyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55b
smwca7d3sbwuurlpublic.urlCorePasteboardFlavorType
0x75726C20public.url-nameCorePasteboardFlavorType
0x75726C6Epublic.utf8-plain-textstringcom.apple.flat-rtfdrich text
datacom.apple.webarchiveApple Web Archive pasteboard
typecom.apple.pasteboard.promised-file-content-typecom.apple.pasteboard.prom
ised-file-urldyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3kNSP
romiseContentsPboardType