Page 1 of 1
Automating PDF export with multiple files
Posted: 2018-05-08 11:49:23
by aersloat
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?
Re: Automating PDF export with multiple files
Posted: 2018-05-09 10:01:33
by Vanceone
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!
Re: Automating PDF export with multiple files
Posted: 2018-05-10 08:35:43
by aersloat
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.
Re: Automating PDF export with multiple files
Posted: 2018-05-12 07:14:30
by Groucho
I wrote this macro years ago. It should work OK with NWP's last version too.
Cheers, Henry
Re: Automating PDF export with multiple files
Posted: 2018-05-14 09:05:25
by aersloat
Thank you very much Henry. I will give it a try.
Re: Automating PDF export with multiple files
Posted: 2018-09-25 09:25:55
by sasha.strong
Hi, I tried this macro, but am running into problems:
Opens the first file in the batch, then responds with
1. A Nisus dialog: "Error while printing."
- error while printing
- Monosnap 2018-09-25 10-19-24.png (30.88 KiB) Viewed 19425 times
[hit OK]
2. A Nisus dialog: "There was an error on Line 14..."
- error on line 14
- Monosnap 2018-09-25 10-20-48.png (42.38 KiB) Viewed 19425 times
[hit Open Macro]
3. Opens the macro and highlights line 14:
- macro text
- Batch Convert RTF to Pdf.nwm 2018-09-25 10-23-20.jpg (78.07 KiB) Viewed 19425 times
I'm running Nisus Writer Pro 2.1.9b on OS X Mavericks 10.9.5.
Any suggestions? I've got dozens of RTFs I would love to convert to PDF for business archives...
Thanks!
-Sasha
Groucho wrote: ↑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
Cheers, Henry
Re: Automating PDF export with multiple files
Posted: 2018-09-26 22:59:20
by phspaelti
This looks to me like "Save As PDF [path]" is broken. Without the path, the command asks to where to save the file (and automatically changes the extension). But with a path it sends the document to the printer (and ignores the path completely).
Time for a bug report.
Re: Automating PDF export with multiple files
Posted: 2018-10-04 10:09:50
by martin
phspaelti wrote: ↑2018-09-26 22:59:20
This looks to me like "Save As PDF [path]" is broken.
The problem here is sandboxing. Even if the user selects the file(s) to convert in an open dialog, that only gives Nisus Writer permission to those specific files. It does not grant Nisus Writer access to the enclosing folder where the PDFs are to be created. That means the PDF export will fail. It's a shame the error message is not more specific; it's a generic error raised by the macOS printing subsystem.
You can fix the problem by adding code to the macro that ensures access to the enclosing folder. For the macro given earlier adding code like this would do the trick:
Code: Select all
$folder = $paths[0].filePathByRemovingLastComponent
File.requireAccessAtPath($folder)
I'll attach an amended macro file. The code assumes that all the selected files are in the same folder.
The new macro is a bit of a nuisance, since it means the user will be prompted twice, but I don't see any way around that. The only workaround would be to rewrite the macro to convert all files in a chosen folder. Selecting that single folder would give Nisus Writer read access to the RTF files and the ability to write PDF files all at once. But I'm guessing that macro is less useful than being able to pick and choose which files to convert.