Re: set var to foo; get var of record?
Re: set var to foo; get var of record?
- Subject: Re: set var to foo; get var of record?
- From: John Delacour <email@hidden>
- Date: Thu, 17 Oct 2002 21:59:21 +0100
- Mac-eudora-version: 5.3a5
At 8:20 pm +0200 17/10/02, Terje Bless wrote:
That is, create a record of key=value pairs, set a variable to one of the
key names, and then fetch the value of the key whose name is in the
variable. Naively, I attempted:
set variable to "key1"
set hash to {key1:"value1", key2:"value2"}
if (hash's variable) then
set result to hash's variable
end if
It is technically possible to do this departing from an AppleScript
record, but it's slow and ugly and not meant to be. This is one of
several thousand fundamental shortcomings in AppleScript.
You'd be far better off putting your array into a list of strings to
start with rather than bothering with AS records, and working with
that rather as you do in perl.
set {key_, value_} to {"key1", false}
set array_ to {"key1", "value1", "key2", "value2"}
repeat with i from 1 to count array_
if i mod 2 is 1 then
if item i of array_ is key_ then
set value_ to item (i + 1) of array_
exit repeat
end if
end if
end repeat
if value_ is not false then return value_
The problem I'm trying to solve is in matching an email address to a
sending account (or "Personality" in Eudora's terms), changing the sending
account depending on which email address originated the message being
replied to. I realise there are other ways to achieve this, but this method
is one I've often wanted in AppleScript (because it works so well in Perl).
Here is how you might set a Eudora personality according to the
address in the From field:
set array_ to {"@pobox.com", "Pianomaker", "@eremita", "Direct"}
(* Eudora personalities are cAsE-sensitive *)
set personality_ to false
tell application "Eudora" to set from_ to field "from" of message ""
repeat with i from 1 to count array_
if i mod 2 is 1 then
if item i of array_ is in from_ then
set personality_ to item (i + 1) of array_
exit repeat
end if
end if
end repeat
tell application "Eudora"
set reply_ to reply front message
if personality_ is not false then
set personality of reply_ to personality personality_
end if
end tell
JD
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.