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 New Roman, 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 "Format:Font:Times New Roman"
Do Menu Macro with macro "Format:Bold"
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.

Examples

tell application "Nisus Writer Pro"

 get text of document 1

end tell

tell application "Nisus Writer Pro"

 get character 3 of word 1 of paragraph 1 of text of document 1

end tell

tell application "Nisus Writer Pro"

  set word 1 of text of document 1 to "Modified Text"

end tell

tell application "Nisus Writer Pro"

  set color of words 1 through 4 of text of document 1 to "green"

end tell

Nisus Writer Pro has a limitation when setting the text in that the changes caused by the AppleScript are not undoable and may cause problems with existing Undo/Redo actions.

Do Menu Macro

You can run any string of text as a Nisus Menu Macro

Examples

set macroString to "Format:Size:Increase" & return & "Format:Font:Apple Chancery"

tell application "Nisus Writer Pro"

   activate

   Do Menu Macro with macro "Edit:Select All"

   Do Menu Macro with macro macroString

end tell

Other examples

This script will insert the path to the front document at the end of the document

tell application "Nisus Writer Pro"

if exists (path of document 1) then

   set thePath to path of document 1

else

   set thePath to "No Path"

end if

make new paragraph at end of text of document 1 with data (return & thePath)

end tell


Previous Chapter
Write AppleScripts
<<  index  >>
 
Next Chapter
Put It All Together