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: Malcolm Fitzgerald <email@hidden>
- Date: Thu, 3 Oct 2002 15:58:13 +1000
Hi Malcolm,
Thanks for your reply. I was testing it a little more, and I ran this code:
---------------------------------------
tell application "AppleWorks 6"
activate
set Txt to document 1's text
set AppleScript's text item delimiters to "D"
set Txt2 to Txt's text items
set AppleScript's text item delimiters to "dTest"
set NewTxt to Txt2's text items as string
set AppleScript's text item delimiters to ""
set document 1's text to NewTxt
end tell
---------------------------------------
with this in an AW document (Hope this shows up correctly in your
email. If not, the word 'BOLD' has been set to bold, the 'D' in
'partly BOLD' is set to bold, 'RED' has been colored red and
'ItaliceD' has been set to italics):
--------------------------------------
Testing with text in AW. This word is BOLD.
This word is partly BOLD. This font is RED. While
this text is ItaliceD. The results?
--------------------------------------
Then, after the Script is ran (being in OS 10.2.1 with AS 1.9) it
gives me this:
-------------------------------------
Testing with text in AW. This word is BOLdTest.
This word is partly BOLdTest. This font is REdTest. While
this text is ItalicedTest. The results?
-------------------------------------
Just in case this doesn't appear correctly in your email:
the word 'BOLdTest' is all bold
the 'dTest' in 'partly BOLdTest' is PLAIN
'REdTest' is all the color red
'ItalicedTest' is all italics.
So, it looks like it's setting the text format of the text that's
been added to whatever the character's text format before it is.
This would be okay, unless there were certain characters in a word
that were set with different text formats (as in the example of
'partly BOLD' with it's last 'D' being the only bold character).
Thought I might share this info. But it sounds like OS 9 has
different issues with AW from your note below.
No, it does not seem as though there are different issues, and thank
you for proving my assertion.
Can you see what's happening to your code?
First, while you have put everything into a tell block directed at
AppleWorks only the first and last lines are handled by AppleWorks.
Everything else is handled by AppleScript. This code gives the same
results:
----------------------------------
tell application "AppleWorks 6" to set Txt to document 1's text
set AppleScript's text item delimiters to "D"
set Txt2 to Txt's text items
set AppleScript's text item delimiters to "dTest"
set NewTxt to Txt2's text items as string
set AppleScript's text item delimiters to ""
tell application "AppleWorks 6" to set document 1's text to NewTxt
----------------------------------
When you look at the results of your example you'll see that the
characters "dTest" take the style of the character immediately
preceding them. In other words, the characters dTest assume the style
of the preceding character, so it becomes bold, italic, red, etc. as
I suggested it would earlier (quoted below)
The "D" from 'partly BOLD' with it's last 'D' being the only bold
character proves this too. By breaking the string into items using
the D (regardless of style info) you were left with a string which
had a plain style run, which was continued. The original bold styling
has been lost forever and if it was important that the final
character of that word be styled in bold text then the method above
isn't doing the job.
The defensible component of my first sally into this thread is this:
many of the methods discussed here are used for string manipulation
rather than for handling styled text. If your text styles are
important you have to use different or complementary methods because
most of techniques discussed here are developed without a glance at
styles. Kai and Michelle raised their voices to say that I'd
over-generalised, there are some here interested in methods for
working with styled text.
You are getting the text of the whole document and replacing the text
of the whole document. Getting and setting sections of the document
may raise further issues. Another consideration is that you've got
all the text styling on the characters of the text. I wonder what
happens to AppleWorks document Styles, ie, the style information that
is stored within the carriage return?
I can answer that, I just tried it, the style of the first character
in the selection is used to determine the over-riding style. Again,
this may not be what you want or expect. I just used your technique
to mess up several really nicely styled lists. Any styles applied
using AppleWorks paragraph or list styles will be replaced by the
style of the first character of the affected text. Any character
level styles will over-ride that paragraph style.
To keep the document styles you probably have to manipulate the
AppleWorks objects in situ - and if you've got high blood pressure or
suffer from stress-related illness I wouldn't suggest it. Much as I
love AppleWorks and AppleScript I don't mix them much.
Also, the text styles aren't intuitive objects. The text styles
info simply says something like "offset 1 thru 5 is bold, Palatino,
14pt", "offset 6 thru 10 is Palatino, 14pt" so if you replace
"small words" with "polysyllabic words" the first five characters
will be bold, the rest plain because the text style info only has
info for a certain number of characters.
--------------------------------------------------
--
Malcolm Fitzgerald
Database Manager
The Australian Society of Authors
phone: 02 9318 0877 fax: 02 9318 0530
http://www.asauthors.org mailto:email@hidden
_______________________________________________
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.