• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: does property exists in a record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: does property exists in a record


  • Subject: Re: does property exists in a record
  • From: "Neal A. Crocker" <email@hidden>
  • Date: Sun, 12 Aug 2001 02:17:31 -0700

Experimentation and serendipity led me to this script, but the original inspiration was a trick described by Olof Hellman in posts to bbs.macscripter.net and to this list along time ago (search the archives) for converting a list of alternating strings and values into a record:


(<< and >> represent chevron characters (Option-\ and Shift-Option-\).)
________SCRIPT by Olaf Hellman_____________
on usrf(theList)
script
{<<class usrf>>:theList}
end script
run script result
end usrf

usrf({"a", 1, "b", "2"}) -- {a:1, b:"2"}
________END of SCRIPT_____________________


There are probably other tricks like this. These tricks just make use of the raw underlying form of compiled applescript in some way that I don't know enough about to try to explain. There are people on this list who probably could. In fact, I wish they would so I could be more systematic about finding such tricks. In fact, I'd like to figure out a similar trick for constructing an appleevent on the fly like this.

Neal.



Good Lord!
Where did you get this information Neal?
Was this something documented somewhere,
or did you cobble together the command line:

{class:reference,<<class form>>:<<constant
****usrp>>, <<class want>>:<<class prop>>,
<<class seld>>:propname,<<class from>>:target}

I would greatly like to know the source of this;
and is there more?

Bryan Kaufman


"Neal A. Crocker" wrote:

play with the script I've included at the end of this message. you
ought to be able modify it to produce a script that generates
references to record fields from strings containing field names.
Such references can be created even for fields that don't exist.
Trying to get the contents of a non-existant record field using a
reference to it will, of course, generate an error. You can use a
try block, much as you've done in the "propertyExists" handler in
you original post, to catch that error and do whatever is necessary
for a non-existant record field.

When playing with the script I've included, be sure to read the
comments in the script. It's tricky to compile. Also, the <<
and >> characters represent chevrons.

Neal.

>Date: Sat, 11 Aug 2001 00:33:51 +1000
>Subject: Re: does property exists in a record
>From: Adam Hinshaw <email@hidden>
>To: <email@hidden>
>
>on 11/08/01 12:14 AM, Paul Skinner at email@hidden wrote:
>
> > I would just look for it. If it's not there then add it.
> >
> > --begin script
> > set x to {hello:"world", goodbye:"cruel world"}
> > try
> > hello of x
> > on error
> > set x to x & {hello:"world"}
> > end try
> > --end script
>
>problem is the property names i will be searching for are not constant.
>They come from strings and will vary.
> >
> >is there a way then to coerce a string to a record property ??
> >
> >doesn't look like it at the moment.
> >
> >adam.
>
> The script below uses << and >> to represent left and right (or is it
right and left) chevrons (Option-\ and Shift-Option-\). Watch for
line wrapping.
______SCRIPT_______________

on makereference(propname, target)
script refscript
--{class:reference,<<class form>>:<<constant
****usrp>>, <<class want>>:<<class prop>>, <<class seld>>:propname,
<<class from>>:target} -- precompiled version of line below
{class:reference, <<class form>>:<<constant
****usrp>>, <<class want>>:property, <<class seld>>:propname,
from:target} -- this line will not compile. must uncoment line above
and remove this line. save copy of commentented line above for
future recompilation.
end script
run script refscript
end makereference

set blah to makereference("bar", {bar:2})
{blah, blah + 1} -- {bar of {bar:2}, 3}
_______________________________________________
applescript-users mailing list
email@hidden
> http://www.lists.apple.com/mailman/listinfo/applescript-users
_______________________________________________
applescript-users mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/applescript-users


References: 
 >Re: does property exists in a record (From: "Neal A. Crocker" <email@hidden>)
 >Re: does property exists in a record (From: Bryan <email@hidden>)

  • Prev by Date: Re: does property exists in a record
  • Next by Date: Re: round 6.0 rounding down -->5 ?
  • Previous by thread: Re: does property exists in a record
  • Next by thread: Re: does property exists in a record
  • Index(es):
    • Date
    • Thread