RE: Replacing Codes with Text
RE: Replacing Codes with Text
- Subject: RE: Replacing Codes with Text
- From: email@hidden
- Date: Fri, 15 Jun 2001 15:56:54 -0500
This is a beautiful thing. I never thought of using two lists like that. You
are correct, I wanted to use a text file so the script's users would be able
to modify or add things to the list whenever they need to. I actually will
be using a variation of this a couple times in my script.
Thanks a bunch, I learned something.
Jim Scharosch
Mac System Administrator
Gazette Communications
319-368-8669
email@hidden
>
----------
>
From: Paul Berkowitz
>
Sent: Friday, June 15, 2001 3:07 PM
>
To: Applescript-Users
>
Cc: email@hidden
>
Subject: Re: Replacing Codes with Text
>
>
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