Re: Records
Re: Records
- Subject: Re: Records
- From: Richard 23 <email@hidden>
- Date: Wed, 28 Feb 2001 21:47:20 -0800
previously posted by olof:
>
>Here's the easiest way to do it using only the standard additions:
>
>
>
>__begin script__
>
>
>
>to usrf(theList)
>
> set n to {<<class usrf>>:theList}
>
> run script "
>
> to run (arg)
>
> arg as record
>
> end run " with parameters n
>
>end usrf
>
>
>
>usrf({"a", 1, "b", 2})
>
>
>
>__ end script__
keeping it clean for the children and easily offended adults, JMBauman
said:
>
Left and right chevrons aside, this is f**king brilliant, ranking up there
>
with Motoyuki Tanaka's [":" as alias as string]. However, I have absolutely
>
no idea why it works, nor any guess as to how you came up with it.
<<class usrf>> is refers to the apple event list which is used to pass
records containing USeR-defined Fields (thus usrf) through the event
manager as I understand it. Predefined fields like "name" are passed
using the four letter code (eg 'pnam').
This can be seen using a tool like Capture AE.
Here's an example:
{user:"R23", name:"Richard 23"}
set the clipboard to result
Capture AE shows:
Process("Script Editor").SendAE "Jons,pClp,'----':
{pnam:"Richard 23", usrf:["user", "R23"]}, &subj:'null'()"
>
The challenge now is how to take advantage of it. Looking up data in a
>
record
>
is much, much faster than looping thru a list of field/value pairs or using
>
the TIDs, but in 9.1 the ability to write a record to a file apparently got
>
damaged, so I need to figure out how to store the resulting record for
>
future
>
use.
Why not use a script object to store records?
Here's a fragment from a recent script to give you the basic idea:
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d4
-- ---------------------------------------------------------
-- author: Richard 23, date: Wednesday, February 28, 2001
-- ---------------------------------------------------------
on save theList in theFile
script StateObj
property parent : AppleScript
property Volume_List : {}
property Alias_List : {}
property Label_List : {}
return {Volume_List, Alias_List, Label_List}
end script
tell StateObj to set {its Volume_List, its Alias_List, its
Label_List} to theList
store script StateObj in file (theFile as string) with replacing
end save
save {volumeList, aliasList, labelList} in (file statePath as file
specification)
-- ---------------------------------------------------------
The return statement is so that the script object can be opened and run to
see the data stored in it in the result window (the stored data isn't
visible) .
>
This is going to occupy valuable parts of my brain for weeks.....
Be careful!
R23