I wrote a sample scriptable app project with Xcode.
It was easy to get parameter in AppleScript Libraries + sdef.
But it is more difficult in Xcode to decode point parameter.
Is there any solution to decode type=“point” parameter in Xcode project?
–Whole Project (Xcode v10.3)
http://piyocast.com/as/wp-content/uploads/2019/08/colorPeeker.zip
–colorPeek.sdef
<?xml version="1.0" encoding="UTF-8"?> <command name="color peek" code="CLP$COPK">
<cocoa class="peekCommand"/>
<parameter name="from" type="file" code="CP$1" description="Image file to peek"/>
<parameter name="at" type="point" code="CP$2" description="Position to peek color"/>
<result description="Color from image {r,g,b}.">
<type type="list" list="yes"/>
</result>
</command>
</suite>
–peekCommand.applescript
script peekCommand
property parent : class "NSScriptCommand"
property aedClass : class "NSAppleEventDescriptor"
property nssClass : class "NSString"
property nsnClass : class "NSNumber"
on performDefaultImplementation()
set paramS to (my directParameter())
set paramDict to my arguments()
set aParam to (paramDict's valueForKey:"from")
log {"aParam", aParam}
set aParam1 to aParam as string
set aFileURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of aParam1)
log {"aURL", aFileURL}
set bParam to (paramDict's valueForKey:"at")
log {"bParam", bParam}
set aDat to current application's NSKeyedUnarchiver's unarchiveObjectWithData:bParam
log {"aDat", aDat}
set xNum to 0
set yNum to 0
set cRes to getColorRGBNumFromImageByPosition(aParam, xNum, yNum) of me
log {"cRes", cRes}
return cRes as list
end performDefaultImplementation
on getColorRGBNumFromImageByPosition(aFileURL, xPos as integer, yPos as integer)
set anNSImage to current application's NSImage's alloc()'s initWithContentsOfURL:aFileURL
set aRawimg to current application's NSBitmapImageRep's imageRepWithData:(anNSImage's TIFFRepresentation())
set aColor to (aRawimg's colorAtX:xPos y:yPos)
set aRed to (aColor's redComponent()) * 255
set aGreen to (aColor's greenComponent()) * 255
set aBlue to (aColor's blueComponent()) * 255
return {aRed as integer, aGreen as integer, aBlue as integer}
end getColorRGBNumFromImageByPosition
end script
–caller AppleScript (on Script Editor)
set aFile to choose file
tell application “colorPeeker”
set aRes to color peek from aFile at {100, 100}
end tell
Model: MacBook Pro 13
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14