Re: Faster way to replace text in AppleWorks?
Re: Faster way to replace text in AppleWorks?
- Subject: Re: Faster way to replace text in AppleWorks?
- From: Nigel Smith <email@hidden>
- Date: Thu, 03 Oct 2002 18:04:53 +0100
On 29/9/02 12:40 pm, "Dale Gillard" <email@hidden> wrote:
>
Hi all
>
>
I have written a script that loops thru an AppleWorks document looking
>
for specific characters and replacing them eg ensuring a period/full
>
stop has a single space after it. As you can imagine, it takes quite a
>
while to do this even in a document of only a few hundred words.
>
>
Does anyone have any advice on how I could speed this up this process?
>
eg a 'you beaut' algorithm that's really fast at doing this rather than
>
my 'naive' algorithm.
It's a shame AppleWorks for OSX doesn't have Macros yet, or you could do
this with recorded Find&Replace routines triggered by AppleScript...
But here's an idea that combines the speed of TIDs with the replacement in
AppleWorks, so you include any styling you want. Basically it involves
1) Grabbing your chunk of text into a variable
2) Splitting it with TIDs to generate a list of offsets
3) Using that list of offsets in AppleWorks to make changes
Here's one that adds an extra space after every fullstop in the first
paragraph of the "macro test.cwk" document. It might start you off on a
faster set of routines...
--------------------------
tell application "AppleWorks 6"
tell document "macro test.cwk"
set {oldTIDs, AppleScript's text item delimiters} to <<break>>
{AppleScript's text item delimiters, "."}
set offsetList to {}
set myList to every text item of (get first paragraph)
set AppleScript's text item delimiters to oldTIDs
repeat with eachItem in myList
set end of offsetList to count of eachItem
end repeat
set offsetCounter to 0
repeat with eachItem in offsetList
set offsetCounter to offsetCounter + eachItem + 1
make new character at character offsetCounter with data space
--increment for the space just added
set offsetCounter to offsetCounter + 1
end repeat
end tell
end tell
-------------------------
Hope that helps,
Nigel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.