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

Page 438: Have applescripts open a new file, Get/set text, Integrate applescript with nisus writer pro 418, Write applescripts for use in nisus writer pro 418, Tasks, Nisus writer pro recognizes

Advertising
background image

418

Writing AppleScripts

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 Pro
users.
AppleScripts are made up of AppleEvents. An AppleEvent is a single command such as Copy or
Print; analogous to a Nisus Writer Pro macro command. Therefore, an AppleScript (an accumulation
of AppleEvents written to perform an action) is analogous to a Nisus Writer Pro macro. There are
several levels of AppleEvent support an application can have.
Nisus Writer Pro supports some of these.
Nisus Writer Pro 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 Pro also supports part of the Text Suite and the “Do Menu Macro”
command.

Integrate AppleScript with Nisus Writer Pro

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

Write AppleScripts for use in Nisus Writer Pro

1. Write AppleScripts in Script Editor.

!

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

Applications/AppleScripts/Script Editor

2. 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 Pro"
Make at front of documents new document
end tell

Have AppleScript open a file and perform some tasks

This script tells Nisus Writer Pro 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 Pro
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 Pro

recognizes

Drop the Nisus Writer Pro 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 Pro are:

getting and setting the text of a document

running Nisus Writer Pro 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