Re: Info about AppleScript records
Re: Info about AppleScript records
- Subject: Re: Info about AppleScript records
- From: Paul Skinner <email@hidden>
- Date: Wed, 09 May 2001 09:45:35 -0400
on 5/8/01 9:29 PM, Malcolm Fitzgerald wrote:
>
>> On 7/05/2001 11:40 PM, "Matthew Broms" <email@hidden> wrote:
>
>>> Specifically right now, I9m looking for a way to dynamically set the
>
>>> key/value pair of a record.
>
>>
>
>> For all practical purposes, you can't. It is really the single modern
>
>> language feature which is missing from AS and is the single biggest handicap
>
>> in terms of using AS as a substitute for Php and asp on web servers.
>
>> Hopefully Apple are at work addressing this limitation...
>
>
>
> Whoa there Tim! You certainly can.
>
>
>
> set datastream to "set x to {key:\"value\"}"
>
> set dynamiclyGeneratedRecord to run script datastream
>
> -->{key:"value"}
>
>
I'd love to do this sort of thing, but of course the thing is to be able to
>
use variable keys. So I wrote:
>
>
set mKey to "asa_serviceType"
>
set mValue to "Manuscript Assessment"
>
set datastream to "set x to {" & mKey & ":\"" & mValue & "\"}"
>
set dynamiclyGeneratedRecord to run script datastream
>
asa_servicetype of dynamiclyGeneratedRecord
>
>
-- returns "Manuscript Assessment"
>
>
but I really need to say
>
>
mKey of dynamiclyGeneratedRecord
>
>
-- returns error: can't get mKey of {asa_servicetype:"Manuscript
>
Assessment"}
>
>
Using run script to get around this doesn't help, as the following shows
>
>
set reqStream to mKey & " of dynamiclyGeneratedRecord"
>
set myReq to run script reqStream
>
>
-- returns "The variable dynamiclyGeneratedRecord wasn't defined"
>
>
> But, some people don't like 'run script' constructions. And they can slow
>
> down execution (supposedly.untested.) if repeatedly used. SO...
>
> If you don't mind OSAXen then you can get RecordAccess from Ed Lai.
>
>
>
> RecordAccess OSAX (Ed Lai - Apple computer 1999)
>
> It allows one to combine two lists to make records, get the keys of a
>
> record as a list and get the value of a given key.
>
> It's available in only one place that I know of. Ed Lai's public folder
>
> on his iTools account. email@hidden.
>
>
>
> --
>
> Paul Skinner
>
>
So I went to look at Ed Lai's RecordAccess OSAX.
>
>
I have the same problem with it: I can't say
>
>
(item 1 of recLabels) of theRecord
>
>
In addition, it returns the record labels in pipes sometimes, but not
>
always. I can't see why but seeing that I can't refer to record labels with
>
list references it doesn't matter much.
>
>
--
>
Malcolm Fitzgerald
Perhaps I should have followed through on my swing...
set dynKey to "asa_serviceType"
set dynValue to "Manuscript Assessment"
set dynamiclyGeneratedRecord to record make from {dynKey, dynValue}
-->{|asa_serviceType|:"Manuscript Assessment"}
get record value of dynKey in dynamiclyGeneratedRecord
-->"Manuscript Assessment"
you could use Ed's OSAX to read from a record generated with run script
by why would you. His solution is much cleaner, concise and readable.
This particular example returns the key in pipes yet the call to get the
record value still works properly when the argument is text.
Moral: Never doubt Ed Lai.
--
Paul Skinner