• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Scriptable ASOC app and records, Part 1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scriptable ASOC app and records, Part 1


  • Subject: Scriptable ASOC app and records, Part 1
  • From: Ron Reuter <email@hidden>
  • Date: Sat, 31 Jan 2015 21:53:30 -0600

In a previous thread, Shane said:

You can return a record if you define a "record-type" type in your sdef. This returns a record with fixed properties.
But you can't return a record with user fields whose properties you define on the fly.

It turns out that both SDEF-based records and user-field records can be returned.
"Easy things should be easy; difficult things should be possible." — attributed to Alan Kay
First, the easy thing: returning an SDEF-defined record type:

In the SDEF file:

<suite name="Test Suite" code="TEST">

<command name="retrieve custom info" code="TESTcust">

<cocoa class="CustomFieldCommand"/>
<result type="custom info"/>
</command>


<record-type name="custom info" code="cInf">
<property name="title"  code="pTit" type="text"    />
<property name="score"  code="pSco" type="integer" />
<property name="active" code="pAct" type="boolean" />
</record-type>

</suite>

Then in the implementation file:

script CustomFieldCommand
property parent : class "NSScriptCommand"


on performDefaultImplementation()


-- For demo purposes, the data is just hard-coded here


set theScore to 100
set theTitle to "Just Because"
set isActive to true


-- return an NSDictionary whose keys match the property names defined in sdef's record-type


set aDict to current application's NSDictionary's ¬
   dictionaryWithDictionary:{score:theScore, title:theTitle, active:isActive}


return aDict
end
end

And finally the test script:

tell application "TestRecordReturn"
   retrieve custom info --> {score:100, title:"Just Because", active:true}
end tell

Notes: 
The  ASOC engine will use the SDEF to interpret the field names (keys) in the NSDictionary the command returns, and will automatically convert it into an AppleScript record.
The keys in the dictionary must match the property names in the SDEF record-type. If they don’t, the engine will silently omit them.
The cocoa class attribute in the command must match the name of the script class, CustomFieldCommand in the example code.

This is relatively simple, and is presented for comparison with the follow-up posting, which will show how to return a user-defined record.

— Ron




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Scriptable application can not return record data (From: Takaaki Naganoya <email@hidden>)
 >Re: Scriptable application can not return record data (From: Shane Stanley <email@hidden>)
 >Re: Scriptable application can not return record data (From: Takaaki Naganoya <email@hidden>)
 >Re: Scriptable application can not return record data (From: Ron Reuter <email@hidden>)
 >Re: Scriptable application can not return record data (From: Shane Stanley <email@hidden>)
 >Re: Scriptable application can not return record data (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Files with full stop preceding not readable.
  • Next by Date: Scriptable ASOC app and records, Part 2
  • Previous by thread: Re: Scriptable application can not return record data
  • Next by thread: Should this be lodged as a TextEdit bug?
  • Index(es):
    • Date
    • Thread