Reply to topic  [ 4 posts ] 
[Newbie First Macro] Insert External Documents (Best practic 
Author Message

Joined: 2015-06-18 10:14:39
Posts: 2
Hi i am new in macro programming in Nisus this is what i would like to achieve:

Main Document:


This is text, etc etc,.




where @@disclaimer@@ i want to introduce the content of disclaimer.rtf from a pre-configured folder
where sign i want to insert the content of a file with the name sign.rtf

Then put the 'full' document at the same directory with an added part to his name like example_print.rtf

I have no experience in macros with Nisus nor perl but i handle regular expressions pretty well and also bash, php, and Apple Script.

With some guidance i know i can do it, any recommendations about 'best practices' or where i can start before noodling inelegant code?

I really want to do my first steps the best i could and write efficient code, and probably here there are many good power users that can share they experience and show me the way to have a better start with Nisus.

By the way, i am new to the community and I want to say hi to the whole community.

Regards from Argentina


PD: I do my best to write as clear as i could but english is not my first language if you find obscure writing please let me know.

2015-06-18 12:42:12
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hello Luciano, and welcome to Nisus.

You ask about recommendations for 'best practices'. That's an interesting question. Unfortunately there is still no good introduction into how to write macros with Nisus. The current resources are the (rather thin and a bit outdated) explanations in the manual, and the Nisus Macro Reference in the Help menu. The latter is essential, but it is a reference, and aims to cover everything rather than be "introductory".
Otherwise the best ideas are to look at macros written by others.
My own philosophy is that, since most macros are about getting tasks done, is to write them as short as possible. If I do plan to keep them around for longer, then I add comments to remember what I was doing. I also like to use variable names that are as descriptive as possible, which means that I often go back and change the variables once I'm done and understand better how the code works.

Finally as to what you will need. The Nisus Macro language is very good and can do pretty much everything you need now, so there is really no need for perl or applescript. The place to start is usually the Find/Replace dialog. Use it to find the parts you want to change, and then use "Macroize" to start the macro. If you need concepts from the Nisus Macro language you will usually add a command like this at the beginning of your code:
$doc =

This will allow you to access all the document properties. Using "$doc" as the variable name for the document seems to be a 'best practice'. I only use other names if I am dealing with more than one document.

Now to what you want to do. The outline would look like this:
  1. Find "@@disclaimer@@" (and save the selection) / Terminate if not found.
  2. Open "disclaimer.rtf"
  3. Copy the text of the disclaimer and insert at the selection (You can use do this without using copy and paste, if you use macro commands instead.)
  4. Close "disclaimer.rtf"
  5. Repeat the steps for the signature
  6. Save at your chosen path


Last edited by phspaelti on 2015-06-22 21:30:08, edited 3 times in total.

2015-06-20 01:55:31
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Here is my version of code that would insert the disclaimer into an open document. I saved the disclaimer in the Nisus Document folder:
$doc =
If ! Find "@@disclaimer@@"
exit 'No disclaimer in this file'

$dmFolder = User Property "document manager folder path"
$disclaimerPath = $dmFolder.filePathByAppendingComponent "disclaimer.rtf"

if File.existsAtPath $disclaimerPath
   $disclaimer = $disclaimerPath, @false
   Insert Text $disclaimer.text


2015-06-20 02:10:24

Joined: 2015-06-18 10:14:39
Posts: 2
Thank you, it really helps me to start with the right feet.

2015-06-22 20:36:54
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software