Writing applescripts, Integrate applescript with nisus writer express, Write applescripts for use in nisus writer express – Nisus Writer Express User Manual

Page 272: Have applescripts open a new file, Get/set text, Examples

Advertising
background image

252

Creating Macros with the Menu Command Dialect

Writing AppleScripts

Using AppleScripts you can create little “stand alone” applications that you can use to take
information from one “scriptable” program and manipulate it in a second one before passing it on to
yet another. You can also create little applications that you can share with other Nisus Writer
Express users.
AppleScripts are made up of AppleEvents. An AppleEvent is a single command such as Copy or
Print; analogous to a Nisus Writer Express macro command. Therefore, an AppleScript (an
accumulation of AppleEvents written to perform an action) is analogous to a Nisus Writer Express
macro. There are several levels of AppleEvent support an application can have.
Nisus Writer Express supports some of these.
Nisus Writer Express is Scriptable. That is, using the Script Editor application, to do any of the
required suite of AppleEvents such as Open - a document, Print - a document, Quit - the
application, Run - the application. Nisus Writer Express also supports part of the Text Suite and the
“Do Menu Macro” command.

Integrate AppleScript with Nisus Writer Express

The argument of the Do Menu Macro can be any Nisus Writer Express menu command (even the
name of a macro, style, etc.). In addition, you can put almost any Nisus Writer Express macro
programming dialect command in an argument. A few examples follow.

Write AppleScripts for use in Nisus Writer Express

1.

Write AppleScripts in Script Editor.

You can find the Script Editor in the AppleScripts folder of the Applications folder.

Applications/AppleScripts/Script Editor

1.

Save your AppleScripts as compiled scripts (with a “.scpt” extension) or plain text (with a
“.applescript” extension) in the folder

~/Library/Application Support/Nisus Writer/Macros

Have AppleScripts open a new file

tell application "Nisus Writer Express"
Make at front of documents new document
end tell

Have AppleScript open a file and perform some tasks

This script tells Nisus Writer Express to open a new file and type “Hello World.” It then selects all
the text, applies the font Times, then makes it Bold and Red.

tell application Nisus Writer Express
Activate
Set newDoc to make at front of documents new document
Set text of newDoc to "Hello World."
Do Menu Macro with macro "Select All"
Do Menu Macro with macro "FormatFontTimes"
Do Menu Macro with macro "FormatBold"
Set color of text of newDoc to "red"
end tell

See a list of all the AppleScripts commands that Nisus Writer Express

recognizes

Drop the Nisus Writer Express application icon on the Script Editor application icon.

Plain text AppleScripts have an extension of 'applescript' and compiled scripts have 'scpt'
The two most useful commands supported Nisus Writer Express are:

getting and setting the text of a document

running Nisus Writer Express menu macros.

Get/Set Text

You can get the main body text of any open document, or any character, word or paragraph of that
text. You can also set the entire body text or any portion of it. You can also get or set the text color
of any piece of the text.

Advertising