Wednesday, November 20, 2019

#1 2019-08-12 07:00:01 am

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

JXA script to call AS Library with sdef

I wrote a simple and stupid AppleScript library with sdef.

http://piyocast.com/as/wp-content/uploa … scptd_.zip

This is the sample AppleScript code.

Applescript:


use AppleScript version "2.5"
use scripting additions
use checkLib : script "checkboxLib"

set tList to {"Carrot", "Burdock", "Radish", "Apple", "Cabbage", "Lettuce", "Potato", "Garlic", "komatsuna", " bok choy", " ashiitake mushroom", "Hen of the Woods"}

set cRes to choose checkbox main message "Select Vegetables" sub message "Select vegetables you like" with columns 2 with titles tList

I tried to write JXA script to call this library.

var app = Application.currentApplication()
app.includeStandardAdditions = true
var alib = Library("checkboxLib")

var array = ["Carrot", "Burdock", "Radish", "Apple", "Cabbage", "Lettuce", "Potato", "Garlic", "komatsuna", " bok choy", " ashiitake mushroom", "Hen of the Woods"]

alib.chooseCheckbox(
{
        mainMessage:"Select Vegetables",
        subMessage:"Select vegetables you like",
        withColumns:1,
        withTitles:array
    }
)

But this causes error...

Error on line 7: Error: -[__NSCFNumber count]: unrecognized selector sent to instance 0xd7649f5ba840a82b

Is there something wrong with it?

Model: iMac Pro
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.


Filed under: Library, JXA

Offline

 

#2 2019-08-12 08:58:37 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 714

Re: JXA script to call AS Library with sdef

Hi,

I downloaded the library from your link. But it is empty.


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#3 2019-08-12 09:16:39 am

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

Re: JXA script to call AS Library with sdef

> But it is empty.

Please drag down the "Result" area separator.
I found the state of the Script Editor's window seems a kind of "empty"
The window seems to be filled with "Result" area.


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

 

#4 2019-08-12 01:08:02 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5105

Re: JXA script to call AS Library with sdef

Hi.

It looks as if it's the array that's causing the problem. The JXA script "works" if the withTitles: parameter is an empty array, a number, or text (or is simply left out).


NG

Offline

 

#5 2019-08-12 06:34:47 pm

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

Re: JXA script to call AS Library with sdef

Thank you. Hmm........I had some trial to avoid error.

I could not recover this :-)


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

 

#6 2019-08-12 08:21:05 pm

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

Re: JXA script to call AS Library with sdef

Takaaki,

The problem is your library's .sdef file. When you call a library from AppleScript the type you specify for the various parameters is basically window-dressing, designed to help the user when they look in the dictionary. But it looks like they matter when bridging to JXA.

You have specified a type of list, but Cocoa scripting does not recognise such a type. You could change it to any, and it should work. But in this case it is probably better to include a type element, with attributes of type and list.

So your .sdef file should look like this:

Applescript:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary>
   <suite name="choose checkbox" code="LCCB" description="Commands for communicating with the user">
       <command name="choose checkbox" code="LCCBCCKB" description="Display checkbox list with an alert dialog">
<parameter name="main message" type="text" code="CMMS" description="Main title of an alert dialog"/>
<parameter name="sub message" type="text" code="CSMS" description="Sub title of an alert dialog"/>
<parameter name="with columns" type="integer" code="CSCS" description="Column number of display checkbox"/>
<parameter name="with titles" code="COLL" description="Titles of every path">
<type type="text" list="yes"/>
</parameter>
       </command>
   </suite>
</dictionary>

Last edited by Shane Stanley (2019-08-12 08:21:32 pm)


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

Online

 

#7 2019-08-12 09:55:48 pm

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

Re: JXA script to call AS Library with sdef

Thanks Shane,

Now, it works from JXA, too.

Model: iMac Pro
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

 

#8 2019-08-13 12:31:02 am

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

Re: JXA script to call AS Library with sdef

Just be aware that there are some quirks where JXA should work but doesn't.

I've had a couple of people contact me about problems calling some handlers of my libraries — in fact, I had one that was most abusive about it roll . But either few people have bothered trying with my libs, or there aren't many JXA users.


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

Online

 

#9 2019-08-13 02:07:54 am

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

Re: JXA script to call AS Library with sdef

I  acknowledge the JXA as a non-AS Osa environment.

Now my small script library's latest version is here.

http://piyocast.com/as/wp-content/uploa … scptd_.zip

It has two enum and the enums have to be usable in limited commands.

So, I made "enu1" and "enu2" data types. It works and displayed as I expected in AS dictionary.

http://piyocast.com/as/wp-content/uploa … 08/cb3.png

But "enu1" and "enu2" are displayed which I didn't hope so.

http://piyocast.com/as/wp-content/uploa … 24x833.png

Is there something wrong with me?


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: Library, JXA

Offline

 

#10 2019-08-13 02:22:21 am

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

Re: JXA script to call AS Library with sdef

You have to give your enumerations unique names and codes, and then use the names as types for the parameters:

Applescript:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary>
   <suite name="choose checkbox" code="LCCB" description="choose list items by checkbox user interface">

       <command name="choose checkbox" code="LCCBCCKB" description="Display checkbox list with an alert dialog">
<parameter name="main message" type="text" code="CMMS" description="Main title of an alert dialog"/>
<parameter name="sub message" type="text" code="CSMS" description="Sub title of an alert dialog"/>
<parameter name="with columns" type="integer" code="CSCS" description="Column number of display checkbox"/>

<parameter name="with titles" code="COLL" description="Titles of every checkbox">
<type type="text" list="yes"/>
</parameter>
<parameter name="checkbox type" type="checkbox types" code="COLC" description="checkbox type"/>
<parameter name="return type" type="return types" code="COLR" description="return data type"/>
       </command>

<enumeration name="checkbox types" code="enu1">
<enumerator name="standard" code="cstd" description="Standard Checkbox"/>
<enumerator name="flat" code="cflt" description="Flat Checkbox"/>
</enumeration>

<enumeration name="return types" code="enu2">
<enumerator name="item number" code="itmn" description="Return data is item number (array of integer)"/>
<enumerator name="data" code="data" description="Return data is each data (array of string)"/>
</enumeration>
   </suite>
</dictionary>

Last edited by Shane Stanley (2019-08-13 05:49:37 am)


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

Online

 

#11 2019-08-13 07:52:16 am

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

Re: JXA script to call AS Library with 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, JXA

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)