Re: Replacing Codes with Text
Re: Replacing Codes with Text
- Subject: Re: Replacing Codes with Text
- From: "Marc K. Myers" <email@hidden>
- Date: Sat, 16 Jun 2001 13:04:19 -0400
- Organization: [very little]
My solution:
set paramFile to (choose file with prompt "Select the parameter file:")
set fileID to (open for access paramFile)
try
set theParams to (read fileID)
close access fileID
on error m number n
close access fileID
error m number n
end try
(*
change from a text file of form "code1 = decode1
code2 = decode2
code3 = decode3... to a list of form {{code1, decode1}, {code2,
decode2}, {code3, decode3}, ...}
*)
set od to AppleScript's text item delimiters
set {od, AppleScript's text item delimiters} to [optn-L]
{AppleScript's text item delimiters, {" = "}}
set theParams to text items of theParams
set AppleScript's text item delimiters to {tab}
set theParams to (theParams as text)
set AppleScript's text item delimiters to od
set theParams to (decompose theParams)
set textFile to (choose file with prompt "Select file to be processed:")
set fileID to (open for access textFile with write permission)
try
set theText to (read fileID)
repeat with anItem in theParams
set AppleScript's text item delimiters to (contents of item 1 of anItem)
set theText to (text items of theText)
set AppleScript's text item delimiters to (contents of item 2 of anItem)
set theText to (theText as text)
end repeat
set AppleScript's text item delimiters to od
set eof fileID to 0
write theText to fileID starting at eof
close access fileID
on error m number n
set AppleScript's text item delimiters to od
try
close access fileID
end try
error m number n
end try
It runs very quickly, but I'd like to know how to use "decompose" to
convert the parameter file to the nested list in a single step.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[6/16/01 1:01:54 PM]