Automating PDF export with multiple files

Get help using and writing Nisus Writer Pro macros.
Post Reply
aersloat
Posts: 7
Joined: 2007-03-27 15:30:36

Automating PDF export with multiple files

Post by aersloat » 2018-05-08 11:49:23

I am looking for a little help with adapting our old workflows using Pages to Nisus Writer Express/Pro. I have a few questions but the first involves some automation. Our main use for NW will be in writing architectural specifications. It is typical for us to have a folder with 20+ individual files that at some point have to be exported to various formats depending on the client or end use. I had an AppleScript wrapped into a Automator Service which would take the selected .pages file(s) in the finder and save them as pdfs. A different Service would export as .doc.

Code: Select all

on run {input, parameters}	
	set theFiles to input	
	tell application "Pages"
		repeat with aFile in theFiles
			open aFile			
			set docPath to path of front document			
			save front document as "SLDocumentTypePDF" in docPath			
			close front document			
		end repeat
	end tell
end run
A very simple script which worked really well for us. From what I gather there is no straight analogy with NW with PDFs specifically. I gather the best way is to create a macro and then call the macro from the Service. If we can do it from the Finder with a service it is preferable in terms of keeping the process smooth.

Any advice on the cleanest way to do this?

Vanceone
Posts: 107
Joined: 2013-05-03 07:06:31

Re: Automating PDF export with multiple files

Post by Vanceone » 2018-05-09 10:01:33

Nisus has limited Applescript support, but one of the things you can do in Applescript is tell Nisus to run a macro.

So I'd build a Nisus macro that saves the document as a PDF.

The "Do Menu Macro With Macro" Command is the one you want. So, your service would be something like this (thanks to Kino):

Code: Select all


set myMacro to "
$doc = Document.active
$docPath = $doc.filePath

# The next three line is unnecessary if you are 100% sure you run this macro
# on saved documents only.
if $docPath == @undefined
	exit 'The document has never been saved, exiting...'
end

# As this macro will change the content of the surrounding folder,
# you may get an error if you don't “require” the access to it. 
# Remove the next two lines if you are running an earlier version of
# Nisus Writer Pro not understanding “File.requireAccessAtPath” command
$folderPath = $docPath.filePathByRemovingLastComponent # Get the folder path
File.requireAccessAtPath $folderPath # For Sandbox access

# Get the path of the pdf file this macro will generate.
# For example, '/Users/you/Documents/sample.pdf'
# for '/Users/you/Documents/sample.rtf'.
$pdfPath = $docPath.filePathByChangingExtension('pdf')

Save As PDF $pdfPath
"

on run {input, parameters}	
	set theFiles to input	
	tell application "Nisus Writer Pro"
		repeat with aFile in theFiles
			open aFile			
			Do Menu Macro with macro myMacro			
			close front document			
		end repeat
	end tell
end run
Now, I had to build in Sandboxing code. This code works best with a folder of documents; the first time you run it with a set of files never done before, it'll ask you to grant access to the file or the folder. Give it access to the folder and you'll never have to worry about it again.

I hope this helps!

aersloat
Posts: 7
Joined: 2007-03-27 15:30:36

Re: Automating PDF export with multiple files

Post by aersloat » 2018-05-10 08:35:43

Thanks for the response. That did not work but hopefully it is pointing me in the correct direction. I have the pdf export macro working from within NW but the integration with AppleScript & Automator is not quite on.

Groucho
Posts: 496
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Automating PDF export with multiple files

Post by Groucho » 2018-05-12 07:14:30

I wrote this macro years ago. It should work OK with NWP's last version too.

Batch Convert RTF to Pdf.zip
(3.37 KiB) Downloaded 12 times

Cheers, Henry

aersloat
Posts: 7
Joined: 2007-03-27 15:30:36

Re: Automating PDF export with multiple files

Post by aersloat » 2018-05-14 09:05:25

Thank you very much Henry. I will give it a try.

Post Reply