• 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: interesting discovery (trying to get record labels as strings )
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: interesting discovery (trying to get record labels as strings )


  • Subject: Re: interesting discovery (trying to get record labels as strings )
  • From: has <email@hidden>
  • Date: Tue, 4 Dec 2001 16:56:31 +0000

Olof Hellman wrote:

>> The problem with records (as others have pointed out) is that
>> calling the keys
>> has to be hardwired into the code. The AppleScript team is
>> apparently working on
>> it, but that probably wouldn't be available for anything less
>> than MacOS X.
>>
>
>Actually no, it doesn't need to be hardwired. That's why I posted my
>extract_exact_usrf handler a few days ago:

Agggh! IT'S ALSO WHY I ever wrote that friggin' hashLib in the first place!
<sigh>Maybe I wasn't clear in explaining it before. OK, one mo' time:

HASHLIB allows you to put data INTO records AND get data OUT OF records -
on the fly - using OBJECTS (e.g. strings) as KEYS. It's FREE, EASY TO USE,
and DOES EVERYTHING YOU NEED for hash-style operations. Oh yeah, and it's
on ScriptBuilders: Download It Now, Or Else.

There, hope that's clarified it.;)

-------

>Note that extract_exact_usrf takes a variable as the key:
>
>
>to extract_exact_usrf(theRecord, fieldName)
> script Fred
> property r : theRecord
> to extract()
> end extract
> end script
>
> set Amy to run script "script George
> property r : {}
> to extract()
> return |" & fieldName & "| of r -- note the bars!!
> end extract
> end
> George"
>
> set Fred's extract to Amy's extract
> return (Fred's extract())
>end extract_exact_usrf

Olof, I'm curious as to why the above is as complex as it is - is there a
reason for this? The following also works, and is somewhat shorter:

======================================================================

to extract_exact_usrf(theRecord, fieldName)
run script "on run{r}
return |" & fieldName & "| of r
end" with parameters {theRecord}
end extract_exact_usrf

extract_exact_usrf({|EU|:3, b:2}, "EU")
--> 3

======================================================================


hashLib's getRecordValue() handler works similarly to the above, though
with one notable difference. Smile's "do script" take external parameters
as "run script" can; instead I have it return a custom-made handler object,
then pass the record into that to get the final result.Here's what it looks
like:

======================================================================

on getRecordValue(theRecord, theLabel)
do script "
script
on thHndlr(param)
" & cnvt's cnvtObjectToLabel(theLabel) & " of param
end thHndlr
end script"
result's thHndlr(theRecord)
end getRecordValue

======================================================================

(Neat trick IMHO. Took me a while to realise it could be done, but it works
like a charm.)


Note: the cnvtObjectToLabel() handler is used to escape any vertical bars
and backward slashes in theLabel so that they won't cause problems. Feel
free to crib it for use with Olof's extract_exact_usrf() handler.

(hashLib also coerces non-string objects to strings, allowing you to use
just about anything as a key.)


Cheers,

has


  • Prev by Date: Re: interesting discovery (trying to get record labels as strings)
  • Next by Date: Re: record labels as strings, etc -- a cut-out-and-keep summary
  • Previous by thread: Re: interesting discovery (trying to get record labels as strings )
  • Next by thread: RE: interesting discovery (trying to get record labels as strings )
  • Index(es):
    • Date
    • Thread