Apple Script Finds and Font commands

J

jgonzo1995

Version: 2008
Operating System: Mac OS X 10.6 (Snow Leopard)
Processor: Intel

Hopefully, someone is able to help me. I'm attempting to write an applescript that scans through a selection of text, identifies all parts that lack a particular formatting characteristic, and then applies a new formatting characteristic to them.

In particular, I hope to be able to select a block of text, and have a script that reduces the font size of any text that is NOT underlined to 8 point.

Frankly, I'm completely lost. Any help would be appreciated.
 
J

John McGhie

You need to use the "Find" object with the "Replace" method.

It's always a challenge programming the Find object, because it is specific.
You must also remember to explicitly set all of the properties of the Find
and Replace objects on the way in to your script, because Word persists the
last settings used in the document for each Find and Replace. So unless you
set the properties inside your script, you do not know what they are, but
you can guarantee that at least some of the time, you won't like them :)

I would first search for "underlined". When you have found Underlined, use
the Replace method to format it with a Style (e.g. "Underlined"). Make your
own style; you need a style of type Character.

Then you come back for a second pass through the text to find anything that
is NOT underlined, and format it with a different style.

When you have it working, substitute the Range object for the Selection
object: it gives you a substantial performance improvement.

But why are you using a script for this? If you set up a Style (e.g. "Body
Text", it's built-in) to be 8 pt, then just click in the paragraph (with no
selection, just an insertion point) and apply Body Text style. That will set
all of the properties of your Body Text style on the paragraph, but will
leave the underlined bits underlined.

If you have first used Find/Replace (from the user interface) to set all the
underlined text to your Underlined style, and made sure that the underlined
style sets a font size) then when you apply the body text style you have
done the job.

Using "Direct Formatting" instead of styles is a bad way to drive Word, and
as you have just discovered, it is a real bear to program around, when you
come to a document formatted that way :)

If you apply styles, the entire document is automatically totally
consistent, and you can instantly change any aspect of the formatting with a
single click.

Sorry, I can't give you an Applescript example, because I am afraid doing
this stuff in Applescript is just too hard :) I stayed in Word 2004 for
serious work, and will cheerfully adopt Word 2010 when it brings VBA back to
the Mac.

Cheers


Version: 2008
Operating System: Mac OS X 10.6 (Snow Leopard)
Processor: Intel

Hopefully, someone is able to help me. I'm attempting to write an applescript
that scans through a selection of text, identifies all parts that lack a
particular formatting characteristic, and then applies a new formatting
characteristic to them.

In particular, I hope to be able to select a block of text, and have a script
that reduces the font size of any text that is NOT underlined to 8 point.

Frankly, I'm completely lost. Any help would be appreciated.


--

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top