On 26 May 2015, at 9:39 pm, Yvan KOENIG <
email@hidden> wrote:
If I understand well the question may be resumed to :
how must we edit the instruction :
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
so that it uses the data extracted from the clipboard.
Yes, you could change it to this:
set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set theData to pb's dataForType:"public.tiff" -- get tiff data off pasteboard
set theImage to current application's NSImage's alloc()'s initWithData:theData
But you already have a tiff representation, so there's no need to make an image to get another one. Then the complete handler becomes quite a bit shorter:
on jpegFromClipToPath:thePath compressFactor:compFactor -- 0.0 = max compression, 1.0 = none
set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set theData to pb's dataForType:"public.tiff" -- get tiff data off pasteboard
if theData = missing value then error "No tiff data found on clipboard"
set newRep to current application's NSBitmapImageRep's imageRepWithData:theData
set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor, NSImageProgressive:false})
set theResult to (theData's writeToFile:thePath atomically:true)
return (theResult = 1)
end jpegFromClipToPath:compressFactor: