• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Learning Applescript for text manipulation?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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]


  • Follow-Ups:
    • say command, out of memory?
      • From: "Joseph A. Weaks" <email@hidden>
  • Prev by Date: Learning Applescript for text manipulation?
  • Next by Date: Re: Memory usage in AppleScript... How to prevent out of memory errors?
  • Previous by thread: Re: Learning AppleScript (was Re: New to the list...)
  • Next by thread: say command, out of memory?
  • Index(es):
    • Date
    • Thread