Wanted: Filename Macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
mchw
Posts: 5
Joined: 2007-07-25 05:51:34

Wanted: Filename Macro

Post by mchw »

Hi,
I am contemplating making the move from Word to Nisus Writer Express. One function that I would really need is to be able to put the filename, the pagenumber & the total number of pages of the document into the footnote section. I can do this manually in 3 steps but I was wondering if there is a Macro to do this with one click.
Thanks
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

This should do it:

Code: Select all

$name = Document Property "File Name Without Extension"
Type Text "$name, page "
Menu ":Insert:Automatic Number:Page Number"
Type Text " of "
Menu ":Insert:Automatic Number:Pages in Document"
Note that the file name is not automatically updating, so if you rename your file you'll have to run the macro again (or edit the header/footer).
mchw
Posts: 5
Joined: 2007-07-25 05:51:34

Post by mchw »

Hi Martin,
Many thanks for the quick reply. Unfortunately I get the folowing compilation error:
"Semicolon seems to be missing at /tmp/NisusScript line 8.
Semicolon seems to be missing at /tmp/NisusScript line 9.
String found where operator expected at /tmp/NisusScript line 10, near "Menu ":Insert:Automatic Number:Page Number""
(Do you need to predeclare Menu?)
Semicolon seems to be missing at /tmp/NisusScript line 10.
Semicolon seems to be missing at /tmp/NisusScript line 11.
String found where operator expected at /tmp/NisusScript line 12, near "Menu ":Insert:Automatic Number:Pages in Document""
(Do you need to predeclare Menu?)
syntax error at /tmp/NisusScript line 9, near "Type Text "
Execution of /tmp/NisusScript aborted due to compilation errors
."
Any ideas?
Thank you
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

My apologies, that macro will only function in Nisus Writer Pro. I should have been more observant with regard to your initial post.

I'm sorry to say there's no single macro that can accomplish what you desire in Express. This is probably the closest:

Code: Select all

#Nisus Macro Block
#source front selection
#destination front selection
#After Execution
#Insert:Automatic Number:Page Number
#End Nisus Macro Block
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

$path = $ARGV[1];
$path =~ /\/([^\/]+?)(\.\w+?)?$/;
$name = $1;
print "$name, page ";
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

I thought about it and there is a solution for you. Save the following as a macro called "Insert Total Pages":

Code: Select all

#Nisus Macro Block
#source front selection
#destination front selection
#After Execution
#Insert:Automatic Number:Pages in Section
#End Nisus Macro Block
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

print " of ";
And then you can make use of this single macro to do what you desire:

Code: Select all

#Nisus Macro Block
#source front selection
#destination front selection
#After Execution
#Insert:Automatic Number:Page Number
#Macro:Insert Total Pages
#End Nisus Macro Block
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

$path = $ARGV[1];
$path =~ /\/([^\/]+?)(\.\w+?)?$/;
$name = $1;
print "$name, page ";
mchw
Posts: 5
Joined: 2007-07-25 05:51:34

Post by mchw »

Many thanks Martin,
That almost works i.e. it pastes the filename and the word "page". It does, however, give an error message about a faulty menu in the macro i.e. "contains an unknown menupath" (I am translating from german) and asks whether to stop or continue the macro.
Michael
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

Michael, you'll need to translate the menu paths to the German equivalents. Just replace the following lines in the macro with German menu names:

Insert:Automatic Number:Page Number
Insert:Automatic Number:Pages in Section
Macro:Insert Total Pages
mchw
Posts: 5
Joined: 2007-07-25 05:51:34

Post by mchw »

D'OH!!
Thanks
mchw
Posts: 5
Joined: 2007-07-25 05:51:34

Post by mchw »

Hi Martin,
I have changed the menu items to their german equivalent but I am getting the same error messages & results i.e. Name of file & "page" are inserted as before. I have checked and rechecked all the items that may need translation but seem to have exhausted all the possibilities.
Michael
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

Can you send your macro via the feedback mechanism? Just use the menu Help > Send Feedback. I'll take a look and see what the problem could be.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

I've thought about this some and this macro should do exactly what you wanted and does not make use of any menu commands, so it will work in the German localization no problem:

Code: Select all

#Nisus Macro Block 
#source front selection 
#destination front selection 
#Send Text as RTF
#End Nisus Macro Block 
use utf8; 
binmode(STDIN, ":utf8"); 
binmode(STDOUT, ":utf8"); 

$path = $ARGV[1]; 
$path =~ /\/([^\/]+?)(\.\w+?)?$/; 
$name = $1;

$rtf = '{\rtf1 \mac{' . $name . ', page {\field {\*\fldinst {PAGE}}} of {\field {\*\fldinst {NUMPAGES}}}}}';

print $rtf;
Post Reply