nisus.com
https://www.nisus.com/forum/

Wanted: Filename Macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=2454
Page 1 of 1

Author:  mchw [ 2007-07-25 05:58:00 ]
Post subject:  Wanted: Filename Macro

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

Author:  martin [ 2007-07-25 09:35:15 ]
Post subject: 

This should do it:
Code:
$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).

Author:  mchw [ 2007-07-25 12:57:58 ]
Post subject: 

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

Author:  martin [ 2007-07-25 13:45:38 ]
Post subject: 

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:
#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 ";

Author:  martin [ 2007-07-25 13:49:35 ]
Post subject: 

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

Code:
#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:
#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 ";

Author:  mchw [ 2007-07-25 16:27:50 ]
Post subject: 

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

Author:  martin [ 2007-07-25 17:35:17 ]
Post subject: 

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

Author:  mchw [ 2007-07-25 21:15:01 ]
Post subject: 

D'OH!!
Thanks

Author:  mchw [ 2007-07-27 03:29:31 ]
Post subject: 

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

Author:  martin [ 2007-07-27 11:52:31 ]
Post subject: 

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.

Author:  martin [ 2007-08-09 11:38:22 ]
Post subject: 

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:
#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;

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/