Re: Learning Applescript for text manipulation?
Re: Learning Applescript for text manipulation?
- Subject: Re: Learning Applescript for text manipulation?
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 18 Jun 2001 02:06:52 -0400
- Organization: [very little]
>
Date: Sun, 17 Jun 2001 23:48:16 -0500
>
To: email@hidden
>
From: "Joseph A. Weaks" <email@hidden>
>
Subject: Learning Applescript for text manipulation?
>
>
Hello,
>
Been lurking for awhile. I'm trying to learn Applescript for a
>
specific use. I want to be able to write scripts to parse text files,
>
interpret beta code tags, change font/keymapping schemes, etc. Most
>
of what I'm talking about is a sequence of find/replace criteria.
>
Many of the text files will be tab delimited.
>
>
What resources, online or book, do you recommend to help me become
>
fluent in these kinds of scripts--working with text files? (I'm
>
still confused a bit on the way to use Applescript's text delimiters,
>
etc.)
I suggest that you take a look at the AppleScript's for Tex-Edit Plus
web site <
http://www.malcolmadams.com/te/index.html>. It has a large
collection of scripts with examples for just about any kind of text
manipulation you can think of.
In vanilla AppleScript you can use AppleScript's text item delimiters to
write very fast scripts that do a simple search and replace. This is
the best formulation of a search/replace handler that I've seen:
on textReplace(theText, srchStrng, replStrng)
tell (a reference to AppleScript's text item delimiters)
set {od, contents} to {contents, {srchStrng}}
try
set {textList, contents} to {(text items of theText), {replStrng}}
set {newText, contents} to {(textList as text), od}
return item 1 of result
on error errMsg number errNbr
set contents to od
error errMsg number errNbr
end try
end tell
end textReplace
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[6/18/01 2:05:16 AM]