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?
Slug Lines
Re: Slug Lines
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?
- martin
- Official Nisus Person
- Posts: 5227
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Slug Lines
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:
So in a document your header could be:
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
When you run the macro that might become:[File Name] @ [Current Date]
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.My Paper @ June 6, 2008