Slug Lines

Get help using and writing Nisus Writer Pro macros.
Post Reply
mwiseman
Posts: 18
Joined: 2008-02-26 13:46:29

Slug Lines

Post by mwiseman »

I know it's a throwback to the days when type was formed from melted lead by guys named Harold with callused hands that could grab hot metal fresh from the Linotype machine and not be burned, but I still like to use "slug lines," a string of text at the top of a document that says information like FileName, Path, Etc. I see where I can have this data appear automatically. How about Character Counts? Is there a way to do a macro that will insert a new top line of text that is FileName, Path, Character Counts and a randomly generated Chuck Norris Joke?

Did you know his tears cure cancer?
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

haha, that joke is new to me.

At the moment there aren't facilities to provide the automatically updating information you'd like. You can use certain macros (eg: Macro > Insert > Document Path) to insert the information, but you'd have to run it any time the information has changed.
User avatar
andreas
Posts: 37
Joined: 2008-05-25 12:41:12
Location: Germany
Contact:

Re: Slug Lines

Post by andreas »

Would it be possible to write a macro that inserts this information (or calls another macro which does) and then sends the document to the printer?
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Slug Lines

Post by martin »

I don't see why not- here's a macro that searches the document for special bracketed templates and replaces them with the corresponding information:

Code: Select all

# This macro duplicates the current document and replaces certain special fields with
# information about the document, then displays the print dialog. The fields take the 
# form "[property]", where "property" is one of a few pre-defined information pieces.
# For the valid property names see the "Replace All" statements at the end of this macro.
$doc = Document.active

# gather some information about the document
$docPath = $doc.filePath
If $docPath
	$docName = $docPath.lastFilePathComponentWithoutExtension
Else
	# unsaved document, just use current display name, eg: "Untitled 2"
	$docName = $doc.displayName
	$docPath = '(unsaved)'
End

# format current date and time
$now = Date.now

$monthName = Date.nameOfMonth($now.month)
$day = $now.day
$year = $now.year
$hour = Date.zeroPad($now.hour)
$minute = Date.zeroPad($now.minute)
$second = Date.zeroPad($now.second)

$currentDate = "$monthName $day, $year"
$currentTime = "$hour:$minute"

# duplicate the document and replace any placeholders with the gathered data
$docCopy = $doc.copy
$docCopy.clearAndDisableUndoHistory		# we're working on a copy, so undo is not needed
If Find All '[file name]'
	Replace All '[file name]', $docName, 's'
End
If Find All ‘[file path]’
	Replace All ‘[file path]’, $docPath, 's'
End
If Find All ‘[current date]’
	Replace All ‘[current date]’, $currentDate, 's'
End
If Find All ‘[current time]’
	Replace All ‘[current time]’, $currentTime, 's'
End
If Find All ‘[current date and time]’
	Replace All ‘[current date and time]’, "$currentDate, $currentTime", 's'
End

# character count must be done last, after making replacements
$docCharCount = $docCopy.text.length
If Find All ‘[character count]’
	Replace All ‘[character count]’, $docCharCount, 's'
End

# print the prepared document
Print
So in a document your header could be:
[File Name] @ [Current Date]
When you run the macro that might become:
My Paper @ June 6, 2008
The Find/Replace All commands in the macro are a bit unusual because NWP seems to sometimes have issue with a direct Replace All involving the headers/footers.
Post Reply