Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: get the properties of a record (Academic Question)



Hmmm, The short answer is probably "no, not really ... but ..."

The real authority on this sort of question is Matt Neuburg. If you don't have his book "AppleScript: The Definitive Guide", I would recommend that you buy it - it is the essential AppleScript reference book. He discusses this in his section on Records. He describes it as "a big shortcoming of AppleScript" that there is "no good way to obtain a list of the names of the items of a record".

You might look at Late Night Software's free List & Record Tools scripting addition, here: <http://www.latenightsw.com/freeware/RecordTools/index.html >. It says on that page: "One of AppleScript's major limitations is that it cannot dynamically access items in records – record keys must be known at compile time. The List & Record Tools scripting addition provides a series of commands for accessing records in a dynamic fashion." (Incidentally, as I am mentioning Late Night Software, if you are not already using their application, Script Debugger, I would strongly recommend that you do: far superior to Script Editor - the essential AppleScript tool.)

Finally, if you are working in AppleScript Studio ... and you have asked this question on the Studio mailing list ...

In AppleScript Studio an AppleScript Record is bridged to Cocoa's NSDictionary, and the key-value pairs of an NSDictionary can be accessed. So, for instance, in Studio you can say:

set myRecord to {a:1, b:2} --> result: {a:1, b:2}
set allValues to call method "allValues" of object myRecord --> result: {1, 2}
set allKeys to call method "allKeys" of object myRecord --> result: {"a", "b"}


To see all the methods of an NSDictionary Object, you'd need to check the documentation for the NSDictionary Class. In XCode go to "Documentation" in the Help menu and search on "NSDictionary", or here's the link to the (same) information on the web: <http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html >

Other people may have thoughts on this question

Philip



On 12 May 2008, at 22:49, Gil Dawson wrote:

Is there a way within an AppleScript script to get the properties of an arbitrary record (i.e., one for which you don't know its properties a priori)?

Both Smile's console and Script Editor's Result window do a fine job of showing an arbitrary record's properties and values, but I don't see a way to do the same thing within AppleScript.

e.g.,

  set myRecord to {a:1, b:2} --> result: {a:1, b:2}

Anyone figured it out?

--Gil
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden
References: 
 >get the properties of a record (Academic Question) (From: Gil Dawson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.