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: Jay Young <email@hidden>
- Date: Thu, 3 Oct 2002 02:03:31 -0500
Hi Malcolm,
You've brought up some excellent points. And I've tested these and see
that they are true. If an AW document does not have any text
formatting set to the text then using the TID method would work,
especially for speed. But I agree that the text formatting should be
displayed correctly in a document once a Script has been run (what a
pain it would be for the user to have to go back and fix all the
formats after they run a Script!). So, in that instance then, the TID
method is definitely not the right approach.
The code I sent Dale would work decently, since it's not changing any
of the words. The only problem would be in this situation:
------------------------------------------------------------------------
------------------------
Testing an exaMplE with the last word set to BOLD. The RESuLT.
------------------------------------------------------------------------
------------------------
In the above example, each capital letter is set to bold. The rest is
plain text (including the periods). When the Script is run, it leaves
all the text formats correctly except that it changes each of the
periods above to bold (since their preceding characters are set to
bold). A way to fix that would be to just change all the periods back
to plain with something like this:
------------------------------------
tell application "AppleWorks 6"
set document 1's (every character where it is ".")'s style to {on
styles:{plain}}
end tell
-----------------------------------
But then again, a period might need to stay bold for some reason, which
messes up that idea.
I don't use AW at all with any of my own projects, but I like to share
ideas with others when they're seeking a solution. Thanks for taking
the time to look a little deeper into this subject. I'll keep in mind
what you've mentioned.
Jay
------------------------------------------------------------------------
-------------
>
> 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.