A better script for AppleWorks
A better script for AppleWorks
- Subject: A better script for AppleWorks
- From: Mr Tea <email@hidden>
- Date: Tue, 30 Apr 2002 02:34:46 +0100
I wrote:
>
If anyone has any suggestions on how to optimise the script
Nothing like going public with a script to sharpen the mind. After trying it
out on Illustrator 10's dictionary and being appalled by the glacial
slowness of the process, I had a rethink.
The original script did a lot of unnecessary selecting, and forced
AppleWorks to do most of the donkey work of figuring out which paragraphs to
indent and collapse. This revised version hands over the calculating chores
to AppleScript, and avoids making any non-essential selections. It's several
orders of magnitude (give or take) faster.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tell application "AppleWorks 6" to set theText to text of document 1
set AppleScript's text item delimiters to tab
set theText to every text item of theText
set AppleScript's text item delimiters to ""
tell application "AppleWorks 6"
activate
set text of document 1 to theText as string
set thePara to index of last paragraph of document 1
repeat until thePara is 1
set endTopic to thePara
repeat until size of character 1 of paragraph thePara of document 1
is 18
set endPara to thePara
set currentPara to endPara
repeat until on styles of style of character 1 of paragraph
thePara of document 1 contains underline
set thePara to currentPara
set currentPara to currentPara - 1
end repeat
set startPara to index of paragraph after paragraph thePara of
document 1
set startTopic to index of paragraph before paragraph thePara of
document 1
if startPara < endPara then
select paragraphs startPara thru endPara of document 1
select menu item "with subtopics" of menu item "move right"
of menu "outline"
select paragraph (startPara - 1) of document 1
select menu item "collapse" of menu "outline"
else
set thePara to thePara - 1
end if
end repeat
if startTopic < endTopic then
select paragraphs startTopic thru endTopic of document 1
select menu item "with subtopics" of menu item "move right" of
menu "outline"
select paragraph (startTopic - 1) of document 1
select menu item "collapse" of menu "outline"
else
set thePara to thePara - 1
end if
end repeat
end tell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enjoy.
Mr Tea
_______________________________________________
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.