Re: Replacing Codes with Text
Re: Replacing Codes with Text
- Subject: Re: Replacing Codes with Text
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 15 Jun 2001 13:07:29 -0700
On 6/15/01 7:40 AM, "email@hidden" <email@hidden> wrote:
>
Is there any way I could set up a text file with all 175 codes and what they
>
equal, along the lines of:
>
agn = Agnes
>
bal = Baldo
>
bmp = Speed Bump
>
bof = Mister Boffo
>
then have the script call it in as a variable and compare one list to the
>
other and build a new list?
That's what records are for. Or just do it as a list of lists. Are you sure
you prefer it as a text file? It could be saved as a property of the script,
in a list of records, or a list of lists. It would be simpler. But maybe you
want to be able to easily add new ones to the text file? OK, I'll do it that
way.
Suppose you keep the "list" in a SimpleText file (or any text file. makes no
difference), with each item on a separate line, and equal signs (" = ")
between the abbreviation and the full name, just as you set out. You can
move the file wherever you want, whenever you want. (It's saved to the
script as an alias.) Here's the script:
---------------------------------------------
property loc : ""
if loc = "" then set loc to choose file with prompt "Where's the text file?"
set list1 to {"agn", "bal", "bmp", "bof"}
set list2 to {}
set f to open for access loc
set r to read f
close access f
set abbrList to {}
set fullnameList to {}
set AppleScript's text item delimiters to {" = "}
repeat with i from 1 to (count paragraphs of r)
set aLine to paragraph i of r
try -- ignore blank lines
set end of fullnameList to text item 2 of aLine --do this one first
to error out of blank lines
set end of abbrList to text item 1 of aLine
end try
end repeat
repeat with j from 1 to (count list1)
set thisAbbr to item j of list1
repeat with k from 1 to (count abbrList)
if thisAbbr = item k of abbrList then
set end of list2 to item k of fullnameList
exit repeat
end if
end repeat
end repeat
list2
-------------------------------------------------
--> {"Agnes", "Baldo", "Speed Bump", "Mister Boffo"}
--
Paul Berkowitz