• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
AppleWorks formatting and Glossary (was: Intro and Can this be done?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AppleWorks formatting and Glossary (was: Intro and Can this be done?)


  • Subject: AppleWorks formatting and Glossary (was: Intro and Can this be done?)
  • From: T&B <email@hidden>
  • Date: Fri, 02 Feb 2001 15:24:25 +1100

Anyway, I have a question for the list. Right now I am finishing up
a glossary for my novel.

I need to go through my entire novel and look for italicized foreign words.

That script segment would be something like:

tell application "AppleWorks 6"
tell text body of front document
get every word whose style is {on styles: italic}
end tell
end tell

stop each time one is found

What exactly do you want to do with each one? If you just want to extract them into another document (such as a database), so you can then fill in a definition of each, you could do this:

tell application "AppleWorks 6"
tell text body of front document
set foreignWords to every word whose style is {on styles:italic}
end tell
make new document at front with properties {document kind:database document} with data {"word", "definition"}
repeat with thisWord in foreignWords
tell database of front document
make new record at end with data {{field:"word", value:thisWord}}
end tell
end repeat
end tell

AppleWorks, perhaps more than any other application, demonstrates a wide range of scriptable environments, such as word processing and database above, making it very powerful.

Of course, you would be better to design your own Glossary database with a pretty layout etc, remove the "make new document" line above, and replace "database of front document" with "database of document "Glossary"".

There is a similar script to this, which provides an "Index..." feature for AppleWorks, described at:
http://www.tandb.com.au/appleworks/index/

probably easier, just change all the
italicized words into bold red ones (and another script to change
them back again later).

A better approach to this reformatting is to define a user style in AppleWorks called "foreign" as italic formatted. When writing or formatting your article, apply that style to the foreign words instead of applying italic directly. Then, at any stage, you can redefine that user style to be red and bold or whatever, and change back again. It will affect every foreign word at once. If necessary, you could discuss such built in AppleWorks features on the forums at:
http://www.tandb.com.au/appleworks/links/

Alternatively, a script can change one formatting to another:

tell application "AppleWorks 6"
tell text body of front document
tell every word whose style is {on styles: italic}
set style to {on styles: bold, off styles : italic}
end tell
end tell
end tell

But it gets a bit trickier to apply color since that is a property of characters only.

So one way to tackle this is to get the index of every matching word, then repeat through them, like this:

tell application "AppleWorks 6"
tell text body of front document
set wordIndexList to index of every word whose style is {on styles:italic}
repeat with wordIndex in wordIndexList
tell word wordIndex
set color of every character to {65335, 0, 0} -- red
set style to {on styles:bold, off styles:italic}
end tell
end repeat
end tell
end tell

I have the _AppleScript Language Guide_ and am searching other
reference material for how to do this.

The most common problem with new or inexperienced scripters, I think, is the lack of early emphasis and understanding of application dictionaries. For this reason, this AppleScript tutorial series was born:
http://www.tandb.com.au/applescript/tutorial/

I have other
AppleWorks formatting tasks that have come up and if I could figure
out how to do those things, I could save a lot of time.

Coincidentally, the above tutorial uses AppleWorks for the exercises, so you learn approaches general to any scripting and specific properties of a typical application. There are also many sample AppleWorks scripts at:
http://www.tandb.com.au/appleworks/scripts/

I have tested all the script snippets above. If you have followup questions, please post back to this list (or one of the AppleWorks ones), not directly to me.

Tom
T&B


  • Prev by Date: Re: loading a subroutine properly
  • Next by Date: powersplit (was Re: Parent property & load script - info)
  • Previous by thread: Parent property & load script - info
  • Next by thread: powersplit (was Re: Parent property & load script - info)
  • Index(es):
    • Date
    • Thread