inserting date/time
-
- Posts: 1
- Joined: 2004-11-12 10:10:33
- Location: Yuba City, CA
inserting date/time
I keep a daily journal. It is convenient to be able to insert, w/o typing, the current date and time. And not updated with each new insertion. Is this possible in NWE?
MP>
MP>
You should be able to do what you want with a macro. Nisus Writer Express comes with one called Date Stamp. This gives a fairly inelegant date format, so I have come up with two other solutions.
One is an AppleScript, which is posted here. You will need to adapt it for your specific set-up.
The other is a Nisus Perl macro, which is more flexible but too long to reproduce here. It inserts the date and/or time in a document at the insertion point. You can edit the macro to set the format you want. Let me know if you're interested in that.
--Craig
One is an AppleScript, which is posted here. You will need to adapt it for your specific set-up.
The other is a Nisus Perl macro, which is more flexible but too long to reproduce here. It inserts the date and/or time in a document at the insertion point. You can edit the macro to set the format you want. Let me know if you're interested in that.
--Craig
The Nisus-supplied macro pastes an ugly, unformatted date/time. Here's a little Perl script I wrote that formats it better. Modify to your heart's content:
Code: Select all
#Nisus Macro Block
#destination clipboard
#source none
#Before Execution
#Clipboard 1
#After Execution
#Paste
#Clipboard 0
#End Nisus Macro Block
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
my $RealMonth = $mon + 1;
if($RealMonth < 10)
{
$RealMonth = "0".$RealMonth; # add a leading zero to one-digit months
}
if($mday < 10)
{
$mday = "0".$mday; # add a leading zero to one-digit days
}
my $TwoDigitYear = $year % 100; #% is the modulo operator.
$merid = "AM";
if($hour >12)
{
$merid = "PM"; # It's after Noon.
$hour = ($hour-12); # dispense with military time.
}
if($hour ==12)
{
$merid = "PM"; # It's after Noon.
}
if($hour <10)
{
$hour = "0".$hour; # add a leading zero to one-digit minutes
}
if($min < 10)
{
$min = "0".$min; # add a leading zero to one-digit minutes
}
printf("%02d/%02d/%02d", $RealMonth, $mday, $TwoDigitYear);
print " $hour:$min$merid";
Last edited by hatchmo on 2004-11-15 12:15:45, edited 1 time in total.
Al Hatch
No, I did.DavidK wrote:Did I do something wrong?
Here’s the procedure:
- (1) Copy the macro
(2) In NWX, select Macro->New Perl Script.
___This will open a new document.
(3) Select All (Cmd-a) and paste the script. Make sure
___that the very first character on the page is a “#“.
(4) Select Macro->Save as Macro...
(5) Name it TimeDate or some such thing.
___It should appear in the macro menu right away.
The two menu commands above don’t do what they say they do.
(1) “New Perl Script” does not make a new perl script. The best I can determine is that the command does no more than “File->New”, and thus is redundant. It gives you the false impression that you are creating some unique kind of document called a Perl Script.
(2) “Save as Macro” doesn’t save as a macro. The only difference between it and “File->Save As...” is that “Save as Macro” picks the proper folder (the Macro folder). It DOES NOT append the proper .pl extension to the end of the document. You must do that by selecting “Nisus Perl Macro” in the “Save As...” dialog.
(3) You must get rid of any spaces at the start and end of all lines. When you copy the script from your browser, NWX pads every line with spaces before and after. Then Nisus complains that it does not recognize the menu commands in the script, because there are spaces after the lines. But it was Nisus that put the damn spaces there in the first place!
(4) For some reason, the code I first posted had a couple of lines missing. Download the corrected code. I've checked it with a copy-and-paste myself.
Last edited by hatchmo on 2004-11-15 12:20:32, edited 2 times in total.
Al Hatch
I found two problems. I'm sorry.
(1) You must get rid of any spaces at the start and end of all lines. When you copy the script from your browser, NWX pads every line with spaces before and after. Then Nisus complains that it does not recognize the menu commands in the script, because there are spaces after the lines. But it was Nisus that put the damn spaces there in the first place!
(2) Also, for some reason, the code I first posted had a couple of lines missing. This is the corrected code. I've check it with a copy and paste myself.
(1) You must get rid of any spaces at the start and end of all lines. When you copy the script from your browser, NWX pads every line with spaces before and after. Then Nisus complains that it does not recognize the menu commands in the script, because there are spaces after the lines. But it was Nisus that put the damn spaces there in the first place!
(2) Also, for some reason, the code I first posted had a couple of lines missing. This is the corrected code. I've check it with a copy and paste myself.
Code: Select all
#Nisus Macro Block
#destination clipboard
#source none
#Before Execution
#Clipboard 1
#After Execution
#Paste
#Clipboard 0
#End Nisus Macro Block
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
my $RealMonth = $mon + 1;
if($RealMonth < 10)
{
$RealMonth = "0".$RealMonth; # add a leading zero to one-digit months
}
if($mday < 10)
{
$mday = "0".$mday; # add a leading zero to one-digit days
}
my $TwoDigitYear = $year % 100; #% is the modulo operator.
$merid = "AM";
if($hour >12)
{
$merid = "PM"; # It's after Noon.
$hour = ($hour-12); # dispense with military time.
}
if($hour ==12)
{
$merid = "PM"; # It's after Noon.
}
if($hour <10)
{
$hour = "0".$hour; # add a leading zero to one-digit minutes
}
if($min < 10)
{
$min = "0".$min; # add a leading zero to one-digit minutes
}
printf("%02d/%02d/%02d", $RealMonth, $mday, $TwoDigitYear);
print " $hour:$min$merid";
Al Hatch
I should have done this in the first place, instead of posting the text of the code:
Here it is: http://homepage.mac.com/animationmaster ... ing15.html
Here it is: http://homepage.mac.com/animationmaster ... ing15.html
Al Hatch
tanks
1) thank you
2) I had no problem, not sure how it happened, but my macro just puts the date in, which is great, I don't want the time
3) I added control/comand 'd' - a menu key for quick adding
PS
if Nisus has been open for a while, and I type command ',' to get my preferences, it crashes
2) I had no problem, not sure how it happened, but my macro just puts the date in, which is great, I don't want the time
3) I added control/comand 'd' - a menu key for quick adding
PS
if Nisus has been open for a while, and I type command ',' to get my preferences, it crashes
I have never let my schooling interfere with my education/Mark Twain (1835-1910)