Re: properties as strings
Re: properties as strings
- Subject: Re: properties as strings
- From: email@hidden
- Date: Tue, 16 Jan 2001 21:11:29 -0500
On Date: Tue, 16 Jan 2001 11:25:35 -0500, Michael Turner
<email@hidden> asked,
>
I would like to collect an entire set of properties from a QuarkXPress
>
object which includes many different kinds of values. I have been unable to
>
convert the list to string by any method, and have resorted to examining the
>
list item by item. Is there a method to convert an entire properties list to
>
string?
In short, use the scripting addition "Sigma's Coersions", by Eric Grant. It
defines a coercion, "as user record", which converts a record into an
alternating list of a field name followed by its data:
{name1: data1, name2: data2} as user record
--> {"name1", data1, "name2", data2}
Vanilla AppleScript doesn't have any way to get record labels from a record
(which is what a QuarkXPress property list is, right? I don't have Quark.) I
usually try and rethink any code where I need this sort of thing. Many people
think they might be able to put record labels in variables and use them like
this:
set selector to month
(selector) of current date
--> hoping for January, but get error "can't get selector of date..."
What they really want is an associative array (what Perl calls a hash).
AppleScript records just don't do that. You generally have to do something
like building an array of pairs, or an array of named records, and searching it
yourself.
to dayLength of someMonth
set monthTable to {{name:"January", days:31}, {name:"February", days:
anything},...}
repeat with case in monthtable
if name of case is someMonth then return days of case
end repeat
return missing value
end dayLength
But back to the issues of a property list. It isn't an associative array; its a
record with properties that change from situation to situation. What is needed
is a capability the Java language refers to as "reflection" Again, AppleScript
doesn't have that, but its easy to do with Sigma's Coercions.
If you will be searching for items within this list, you can use "offset in
list" from ACME Script Widgets and specify "searching odd items returning next
item". Or, you can first deinterleave the list into {{name1, value1}, {name2,
value2},...} pairs, and use ACME lookup field from ACME Script Widgets. Or you
can search the list by hand, without an osax.
You might also want to look at Akua Sweet's "collect items of", which allows you
to go into a subrecord and get its property named in a string. But using it for
this purpose is a bit off-the-point of what collect items was meant to do.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden