The easiest solution would be to change the default app for PDF documents in the Finder. If that’s not desired, which PDF app do you actually use, is it scriptable?
Thanks for the suggestion. Well, I’d prefer that MarginNote could be the default PDF for DTP – but I’d generally prefer my remaining PDFs outside of DTP to open in Preview. So, I don’t think that’ll work. Thanks, though.
Can you elaborate more on your question re: whether MarginNote is scriptable?
Create your own shortcut in the System Preferences>Keyboard>Shortcuts menu. macOS will find and open MarginNote in the Data>Open With menu when a PDF is selected.
Just to be clear, DTP already has MarginNote as an option when using the “Open With menu” – it’s just a very long menu to scroll through and select, which is why a Toolbar shortcut might be a faster option.
Correct, and if you do not have a document selected that can be opened with MarginNote, the shortcut key will not do anything as the OS cannot find a menu with that name.
If you are wanting a toolbar shortcut there is a way through Applescript and the before mentioned solution. Once you have set up the keyboard shortcut as previously described create an Applescript with the following code:
delay 1
tell application "System Events" to keystroke "m" using {command down, option down, control down}
Save the Applescript in the following path: ‘/Users/username/Library/Application Support/DEVONthink Pro 2/Scripts/Toolbar’
Restart DevonThink and then go to the ‘Customize toolbar…’ menu item and drag the script onto the toolbar (you could give the script a nice icon). Pressing the icon should now open the PDF in MarginNote.
There might be a more elegant way to do this if MarginNote has AppleScript support (I have no idea whether it does or not).
MarginNote is not scriptable. But (and I’d strongly advocate this over using System Events for keypresses), if you had to have a Toolbar button, just use this code for the AppleScript (and it requires no shortcuts to be assigned)…
tell application id "DNtp"
if selection ≠ {} then
set sel to (item 1 of (selection as list))
if (type of sel) = PDF document then
set recPath to (path of sel as string)
do shell script "open -a 'MarginNote X' " & (quoted form of recPath)
else
display alert "Please select a PDF file."
end if
end if
end tell
If you have Keyboard Maestro (which is my new favorite tool/toy), you can also set up a hotkey to get a short menu of choices to open in. For example, ⌘O and ⌘⇧O are both standard, but ⌘⌥O lets me open up a PDF in MarginNote or PDFpenPro or even Preview.
Just to extend Jim’s script a little more you could add in a dialog box if there are a number of PDF applications that you might use (I will often use Highlights or PDF Expert for annotations). For example:
tell application id "DNtp"
if selection ≠ {} then
set sel to (item 1 of (selection as list))
if (type of sel) = PDF document then
set recPath to (path of sel as string)
else
display alert "Please select a PDF file."
end if
end if
end tell
set theApplication to (choose from list {"PDF Expert", "Highlights", "Preview", "PDFpenPro"} with prompt "Choose application") as string
if theApplication is "false" then
error number -128
else
do shell script "open -a '" & theApplication & "' " & (quoted form of recPath)
end if
And to extend @kseggleton’s extension of my approach:
Change the appropriate line to this instead…
set theApplication to (choose from list {"PDF Expert", "Highlights", "Preview", "PDFpenPro"} with prompt "Choose application" default items "Highlights" without empty selection allowed and multiple selections allowed) as string
… and set the most often used one as the default. This allows for an invocation and a quick tap of the Return key in the majority of the cases, but still gives you choices for those other moments in life.
Note: Since there is a default item specified, the without empty selection is redundant, but it’s good form (and a good learning tool to see the option is available).
I have just discovered another way of quickly opening a file in an external application (although it uses the keyboard rather than the toolbar) and that is to use Alfred. Alfred’s file action will act in DevonThink. This means that you can invoke Alfred’s file action with a shortcut, press the shortcut for ‘Open with’, start typing the name of the Application to open the file with and press enter. Will also work with emailing files from DevonThink, copying Finder path and revealing file in Finder.
Nice tip! For the LaunchBar users, LB works well to do the same with its Instant Send feature. Select a document, hit the Instant Send shortcut (I use double-command key), and you will have all the same open, email, message, ect. options that Alfred has. I really wish Alfred had the same, Instant Send functionality as that’s probably the only thing that keeps me using LB instead of Alfred.