Re: Help with find text command
Re: Help with find text command
- Subject: Re: Help with find text command
- From: Philip Aker <email@hidden>
- Date: Sun, 12 Aug 2007 22:16:34 -0700
On 2007-08-07, at 12:23:17, Wallace, William wrote:
Just for kicks, here is the full text of the script I ended up
with. It did what I needed it to in a reasonable amount of time so
I am happy with it, but I'd also be curious to hear any comments or
critiques from the "bake-off" crew (or anybody else who cares to
comment). I'm always glad to leaern how I could do things better.
Hi William,
I see you're obligated to do the replacements backwards through the
story whereas the test situation takes advantage of the fact that a
regsub can proceed forwards without having to use any of the splicing
techniques required for an AppleScript equivalent.
I created an AppleScript to produce the specified HTML document using
Satimage.osax (3.1.8) however there appears to be a bug in it when
used from a Terminal and I could not get a comparative timing from
the shell script. However, it would run in Script Editor, and
compared to the "pure AppleScript" example I provided, the time for
1000 iterations was approximately 30 times faster. I used the
're_compile' command in Satimage to pre-compile the regular
expression (as a script property) and think that your script could be
sped up slightly by the same technique.
For the purposes of HTML output, I couldn't figure out whether or not
the Satimage 'change' commands (i.e. regsub) could be configured to
do a single replacement and also think that the gargantuan regular
expression you used for the 'find text' is no more effective than the
shorter versions Mark and I used in our scripts (we simply tested the
found length). That's because the Satimage 'change' command
incorrectly changed a found ISBN-13 when provided with the same pre-
compiled regular expression.
In the process of these comparisons, I also created a TclOSAX to see
whether or not I could use the Tcl regular expression calls more
directly in AppleScript. It worked both from Script Editor and an
osascript call, and I've included it in the timing tests. The example
script ("isbnTclOsaxIndices.scpt") uses the same technique of walking
backwards through the text and replacing a single found item.
I don't use either of the apps you have to work with but googled for
InDesign and noticed that the latest version offers XML and suggests
XSLT solutions can be used. If that's the case for your version, I
expect that an XSLT would provide the most reliable method for both
locating and replacing the ISBNs. If you could export/translate the
lookup table from Excel to an XML document, the XSLT could handle
everything (using either the so called Muenchian method or <xsl:for-
each-group …>).
Anyway, thank for bringing the ISBN search up. In the process of
trying to optimize the Tcl version I discovered a way to get the
search and replace method to a single line (which relies on two tiny
functions for support). I will include it in a subsequent version of
the tests: <http://homepage.mac.com/philip_aker/dl/code/TestISBN.zip>.
Cheers,
Philip Aker
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden