Automate: Export to PDF

Here is a challenge:

How can I export an OmniOutliner document without using a mouse? I have to generate a PDF of an OmniOutliner document several times a day. Ultimately, I’m trying to automate the process using Keyboard Maestro.

Any ideas? Automator?

It would be great if OmniOutliner could simply export to PDF.

Keyboard Maestro should work.

Command-P opens the File/Print command, then Alt-P saves it as a .pdf.

You can then use the default values for Save As and Where, or have KM enter new values, tabbing from one to the next.

No mouse.

This script works here:

tell application "OmniOutliner"
	activate
	set winName to front document's name
	tell application "System Events"
		tell process "OmniOutliner"
			keystroke "p" using command down
			click window winName's sheet 1's menu button "PDF"
			keystroke "p" using command down
			keystroke return
		end tell
	end tell
end tell

You could attach that to a keyboard shortcut using KM (which I don’t use)

Or you can create an Automator Service in Automator and attach that to a keyboard shortcut. Fire up Automator, choose ‘Service’ as the document type, drag a ‘Run AppleScript’ action from the left into the right pane, copy-paste the script into the 'Run AppleScript action (replacing all the existing suggested code) and set the Service at the top to receive ‘no input’ in ‘OmniOutliner’ (scroll down after clicking Other…") Save as ‘Save to PDF’ or whatever.

This will add an item to your OmniOutliner > Services menu. Then make sure ‘OmniOutliner.app’ and ‘Automator.app’ are checked at System Preferences > Security & Privacy > Privacy > Accessibility.

And to attach the keyboard shortcut, go to System Preferences > Keyboard > Shortcuts > Services and type the shortcut you want in the right column next to ‘Save to PDF’ (or whatever you’ve named the Service). You have to make sure it doesn’t conflict with other shortcuts. Option-command-p did the trick here.

SG

Sorry - I didn’t realize that Alt-P was a Keyboard Maestro macro I’d already made. Anyway, it’s easy, and here are the steps:

I don’t have KM, but what the AppleScript does is simulate:

  1. command-p
  2. click ‘PDF’ button
  3. command-p
  4. return

Those Down Arrows needed?

SG

Hi SGIII,

The two down arrows get me to “Save as PDF”, much like your command-p takes us to “Save as Adobe PDF”. Speaking of which … is there a difference?

RB

I think the end result is the same (though I don’t have KM to test).

However, in AppleScript having fewer steps in a GUI script is noticeably faster (a command-p vs two down arrows).

SG

Interesting.

I just did a little test, and edited my KM macro to “Save as Adobe PDF”, and it actually added an extra step. After I chose “Save as Adobe PDF”, it opened a window asking for “Adobe PDF settings” and “After PDF Creation”.

Those don’t come up if one uses “Save as PDF” instead of “Save as Adobe PDF”.

FWIW.

“Save as Adobe PDF”, and it actually added an extra step. After I chose “Save as Adobe PDF”, it opened a window asking for “Adobe PDF settings” and “After PDF Creation”.

I don’t have ‘Save as Adobe PDF’ as an option. Maybe you have Acrobat installed?

Here ‘Save as PDF…’ works well, though. Step 3 of my 4-step sequence above gets me there.

SG

Yup. I do have Acrobat installed.

One of the first things I set up on a Mac. Cmd P is muscle memory. https://www.macsparky.com/blog/2013/10/print-to-pdf-revisited

1 Like

Thanks for posting the MacSparky trick, command-p command-p. However, that does not work on my machine. Have you tested it on yours with OO?

It doesn’t work here because I need step 2 in my sequence above (click the ‘PDF’ button) before proceeding to step 3 (another command-p).

Have you done something special on your Mac to avoid having to click the ‘PDF’ button?

SG

@SGIII Perhaps you are on Sierra with its (shudder) PDF woes? I don’t think I had to do anything other than what David Sparks showed in that video (allowing for some minor OS version differences).

Here’s what my print sheet looks like from OO4 Pro when invoking Command-P.

I can press Command-P again to get the save file dialog box. If instead I click the PDF button on the print sheet, I see these options. You can see I added Command-D to save to DEVONthink Pro Office as well.

I am on El Capitan using OmniOutliner 4 Professional. It works on the OO5 beta as well.

@TheWart I am indeed on Sierra, and am happy with it. No pdf woes here (though I was sad to note the demise of the ability to use convert on the command line to convert from rtf to pdf).

I have tested the 4 steps outlined above with OO5 (beta), and they work well. The GUI script that implements those 4 steps has no dependencies on KM or on staying with an old version of the OS. One keyboard shortcut (I’ve assigned option-command-p) and I’m done.

SG