[X4U] Apple script and numbering

Bill White billwhite at mac.com
Tue Mar 29 05:53:35 PST 2005


On 3/28/05 9:40 PM, Jerry Krinock <jerry at ieee.org> wrote:

> on 05/03/26 05:56, FC Farwell at frankfarwell at mac.com wrote:
> 
>> How would one write an apple script for AppleWorks that will find numbers,
>> starting with a certain number let's say 10 for example in a pages of text
>> and raise each one it finds to the next highest number?
>> 
> If this is possible, I would say it would take an AppleScript expert at least
> an hour to get this running and debugged.

LOL! While it may take some time to debug it, the following took me exactly
three minutes to write. This replaces all occurrences of 10 with 11; is that
what you're after? Or are you trying to replace all 10s with 11s, 11s with
12s, etc? Is would be simple to modify to do that.

-----------------------

tell application "AppleWorks 6"
    
    set origText to text body of document 1
    
    set AppleScript's text item delimiters to "10" -- change to suit
    
    set tempText to text items of origText
    
    set AppleScript's text item delimiters to "11" -- change to suit
    
    set newText to tempText as string
    
    set AppleScript's text item delimiters to ""
    
    set text body of document 1 to newText
    
end tell

-----------------------

A couple notes: text item delimiters are AppleScript's extremely fast way of
breaking up chunks of text; the script above essentially breaks up the text
of the front most AppleWorks document everywhere it finds a "10", glues the
pieces back together putting an "11" in their place, and replaces the
original text with the modified text.

I don't use AppleWorks myself, but launched a copy of it to check its
dictionary and test this little snippet. The script above will probably fail
for an extremely large document, but you'd have to try it and see.

-- Bill 




More information about the X4U mailing list