Re: Scriptable Search-and-Replace Utilities
Re: Scriptable Search-and-Replace Utilities
- Subject: Re: Scriptable Search-and-Replace Utilities
- From: has <email@hidden>
- Date: Tue, 15 Jan 2002 00:14:52 +0000
Kirk Kerekes wrote:
>
> I am searching for a search-and-replace utility that is AppleScript-able.
>
> I've begun testing Text Machine, but I'd like to have some outside opinions
>
> of it. I'd also like to know if there are other scriptable s-and-r
>
> utilities and what users think of them.
>
>
Consider AppleScript itself. The replace_chars routine offered in the
>
Essential Subroutines section of the AppleScript Guidebook:
>
>
on replace_chars(this_text, search_string, replacement_string)
[snip]
>
>
-- is remarkably quick due to its use of the highly optimized Text Item
>
Delimiters function, and gains additional effective speed by not having to
>
use inter-application communication to do the work. I use it all the time
>
for fairly heavy-duty tasks like automated web-page creation for database
>
publishing. I have yet to break it.
Actually, it'll break very easily if there's more than a few thousand
matches made (depending on what you're doing, this may or may not be a
problem). There's a more robust version I've done on AppleMods at
macscripter.com; it also has an option for doing multiple find-and-replaces
without risk of later replaces overwriting earlier replacements.
Something else to note is that the basic TID-based F&R routine is case
sensitive. Again, whether or not this is an issue for you depends on what
you're doing. I have written one that gives respectable performance (it's
TID-based, with some extra stuff thrown in to make it caseless) though it's
currently unreleased (I've been too busy on other stuff to finish the
feature set and documentation, but what's there works).
For more powerful searching, e.g. matching whole words only, your best bet
is a scriptable text editor or a regular expression scripting addition.
There's several of the latter kicking about; my current preference is
leaning towards the Satimage osax (with caveat). It does F&R with options
for ignoring case and support for both normal searches and regular
expression-based ones. The caveat I know of is that I put in a couple of
bug reports on it before Christmas, but I don't know if they've been fixed
yet (maybe Emmanuel could tell us?). However, it does have the advantage of
being both classic and OS X savvy (other F&R osaxen aren't), and I expect
the bugs will be fixed before long.
HTH
has