inserting date/time

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
G. Michael Paine
Posts: 1
Joined: 2004-11-12 10:10:33
Location: Yuba City, CA

inserting date/time

Post by G. Michael Paine »

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>
Jamie
Posts: 1
Joined: 2004-11-12 11:53:34
Location: Clermont, FL
Contact:

Post by Jamie »

There's a Date/Time Stamp in the Macro Window.

Jamie
cchapin
Posts: 424
Joined: 2004-02-25 18:28:40
Location: Nagoya, Japan

Post by cchapin »

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
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

Post by hatchmo »

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
DavidK
Posts: 72
Joined: 2004-10-26 15:35:19
Location: Grand Rapids, MI

Post by DavidK »

How do I take the perl macro text that hatchmo so kindly posted and turn it into a macro? I tried copying, opening a new macro document, pasting it, and saving as a perl macro. But when I tried running it, I got a couple errors. Did I do something wrong?

David
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

Post by hatchmo »

DavidK wrote:Did I do something wrong?
No, I did.

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.
Cautions:

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
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

Post by hatchmo »

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.

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
midwinter
Posts: 333
Joined: 2004-09-09 18:07:11
Location: Utah
Contact:

Post by midwinter »

Can someone make that available for download somewhere? I'll happily put it on my iDisk if'n someone would email it to me as a macro.
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

Post by hatchmo »

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
Al Hatch
gemboy27
Posts: 355
Joined: 2003-09-30 21:33:58

tanks

Post by gemboy27 »

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
I have never let my schooling interfere with my education/Mark Twain (1835-1910)
Post Reply