Re: Records
Re: Records
- Subject: Re: Records
- From: has <email@hidden>
- Date: Wed, 28 Sep 2005 09:41:39 +0100
Matt Neuburg wrote:
> >getting names from records is a PITA.
>
>This question is probably the most FAQ of all. I have seen long complicated
>kludges that purport to "solve" this vexing lack of introspection.
The problem's less lack of introspection and more that AppleScript's designers decided to bridge AERecords (which are key-value lists) to AS's inflexible struct-like record type (a fixed collection of properties) rather than to a more flexible hash type (a key-value map). Perl and Python, for example, both map AERecords to hashes/dicts so this isn't a problem there; e.g.:
#!/usr/bin/env pythonw
from appscript import *
print app('Font Book').typefaces[1].typeface_additional_info.get().items()
>However,
>there is now a much better way: Use the List & Records osax from Late Night
>Software.
List & Record Tools is useful, but note that it has a couple significant limitations: you can't it pass records that contain references to other applications, and values that are mutable data structures will be duplicated so you get pack copies, not the originals. (These are limitations of Apple events, btw, not the osax itself.) e.g.:
tell application "Finder" to set rec to properties of home
get property "pnam" in rec
--> Error: Can't make «class cfol» "Users" of «class sdsk» of application "Finder" into the expected type.
I don't think these will be an issue in Martin's case, so he should use the L&R osax if he can as it's the most reliable solution for AppleScript users within those limitations.
Alternatively, AppleMods' Record library provides a recToList() command that doesn't have these limitations; it is based on the nasty old error string parsing hack so there's no guarantee it'll always work correctly, but (touch wood:) the parser is quite robust and it's been tested with a variety of data without any apparent problems.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden