Friday, September 20, 2019

#1 2019-08-22 01:11:28 am

maro
Member
From:: Nerima, Tokyo, Japan
Registered: 2004-05-30
Posts: 22
Website

decode point parameter in Xcode-based scriptable app

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/uploa … Peeker.zip

--colorPeek.sdef
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="colorPeeker">
    <suite name="Color Peeker Command Suite" code="CLP$" description="Specific classes and commands for this application.">
       
         <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>
</dictionary>


--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


I wrote thousands of AppleScript to realize my idea. Natural language interface, voice recognition commander and so on. Though my mother toungue is strange language, Japanese, my most frequently write language is AppleScript. I believe it is for making things easy and powerful.

Offline

 

#2 2019-08-22 02:05:00 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5898

Re: decode point parameter in Xcode-based scriptable app

Don't use the point type — use a list of integers or reals instead. You can't easily translate the point type.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-08-22 02:36:12 am

maro
Member
From:: Nerima, Tokyo, Japan
Registered: 2004-05-30
Posts: 22
Website

Re: decode point parameter in Xcode-based scriptable app

Thanks, Shane!

Now, I can prepare point-like data via sdef.


I wrote thousands of AppleScript to realize my idea. Natural language interface, voice recognition commander and so on. Though my mother toungue is strange language, Japanese, my most frequently write language is AppleScript. I believe it is for making things easy and powerful.


Filed under: sdef

Offline

 

#4 2019-08-22 09:43:37 am

maro
Member
From:: Nerima, Tokyo, Japan
Registered: 2004-05-30
Posts: 22
Website

Re: decode point parameter in Xcode-based scriptable app

Additional Info. I referred this to return error to caller script.

objective c How do I add Applescript support to my Cocoa application?
https://code-examples.net/en/q/25d5e1#header


I wrote thousands of AppleScript to realize my idea. Natural language interface, voice recognition commander and so on. Though my mother toungue is strange language, Japanese, my most frequently write language is AppleScript. I believe it is for making things easy and powerful.


Filed under: sdef

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)