Open PDF File URL with Preview

Any ideas how I could make a macro that opens a PDF file located at a URL with Preview? I would like to quickly see changes made to a PDF file at a URL but have it in Preview if possible.

I can go to open URL but that would of course just open in the default browser.

Since Mac Preview app works only with files on your local drive, I don't think there is much chance of this working, without first downloading the file.

The first step would be to figure out a method to do it manually. Then, you can try to automate it with KM. I would imagine an Internet search is in order.

Good luck.

Thanks, I was thinking that there might be a way since you can right click on the file and say open with Preview. It downloads it somewhere but you can’t command click on the Preview file name to see the path.

The problem is I don’t always have the Safari window on the same display so I can’t do manual mouse move and right click to choose that option.

On a file, yes, but not on a link. When I right-click on a link to a PDF, I do NOT see any choices to open with Preview:

If you are seeing something different, please post a screenshot so we can understand.

Sorry that wasn't clear, I meant when I right click on a PDF in Safari I get the option to open in Preview. I do realize that if I had another PDF plug-in installed like Acrobat or other third party browser PDF plug-ins the option might not be there on a right click or found elsewhere. I have removed all 3rd party browser PDF plug-ins.

I can confirm that. Interesting that the "Open in Preview" option appears in Safari, but not in Chrome.

Given that, there is a reasonable chance that you could use AppleScript to tell Safari to open the PDF in Preview. I don't know how to do that off the top of my head, but if @ccstone is around, then he would know if anyone does.

Of course, in reality, the PDF is being downloaded behind the scenes so that Safari can open it in Preview. Given that, you could download the PDF, then you would have a file you could open in Preview.

May I ask what is the advantage of opening it in Preview, vs just viewing it in the browser?

[quote="skillet, post:3, topic:4937, full:true"]
Thanks, I was thinking that there might be a way since you can right click on the file and say open with Preview. It downloads it somewhere but you can't command click on the Preview file name to see the path. [/quote]

Command-clicking the title bar icon doesn't show anything because the file is an unsaved cached version at that point. You can save the file if you'd like, then clicking the title bar icon will show the hierarchical menu that's normally seen. If you wanted to automate all that with Keyboard Maestro, you could do the following.

  1. Go to System Preferences > Keyboard > Shortcuts and create a Safari-specific shortcut for the menu item Open PDF in Preview (exact case matters) and assign a shortcut, Like Command-P (yes, that's for Print, but it will work here without affecting the Print command).

  2. Go to Keyboard Maestro and create a new Safari-specific macro. Give it a trigger of some sort (in my head I would use Command-Shift-P). Set the macro to

  3. Simulate pressing Command-P (or to select File > Print...).

  4. Pause for a second.

  5. Press Command-P (since the Print dialog is now open, this is invoking the Open PDF in Preview command, not the option to Print).

  6. This throws the PDF over to Preview, which can take a second or three depending on the size of the PDF. I'd set KM to watch for Preview, then simulate a

  7. Command-S to save the Preview that's now open in Preview.

You may need to adjust any pauses to account for the speed of your Mac.

A plain and simple solution would be to watch the Download folder and open the PDF with preview. You find a macro here.

In case you don’t know: if you Option-click a PDF link in Safari it will directly download the PDF to the Downloads folder, without opening it in the browser. (This works for links that are not set to open in a new browser window.)

PS: If you are worried about cluttering your Downloads folder with PDFs, you can build another macro with a periodic trigger that removes PDFs from that folder once a week or so.

1 Like

I love this feature and have been doing that for a years since David Sparks first made this very nice suggestion. I probably do that a couple times a day at least and just set that up through the OS for a friend last week that was doing this a lot.

The problem with that though is that an indexed PDF is no longer indexed.[quote="Tom, post:8, topic:4937"]
If you are worried about cluttering your Downloads folder with PDFs, you can build another macro with a periodic trigger that removes PDFs from that folder once a week or so.
[/quote]

Yes I would probably have to do that since I might open the same file multiple times in one day. I do use that option clicking thing every now and then. I like that the file seems to reside in cache and that I don't really have to worry about deleting anything when done and the file name changing as the PDF gets updated but with the same name.

Anyway thank you for all the help, I might just do something relative to the front window in the mean time after waiting for the window to load.

I presume you mean indexed by Spotlight. If that's correct, once the file is saved it will only be moments before Spotlight indexes the new PDF. Or maybe you mean something else by "indexed"?

I have the strong suspicion that you are re-creating the PDF via the Print dialog (-> “David Sparks”?). Is this correct?

If you create a PDF through the Print dialog both the PDF index and the PDF bookmarks (aka Table of contents) are lost. This is because you are actually creating kind of “a PDF from a PDF” with the system’s PDF engine (Quartz).

This step is not necessary, since the PDF is already downloaded:

  • if you “directly” download it (Option-click) it’ll be in the Downloads folder,
  • if you load it in Safari, it’ll be in the systems’s temporary folder (/private/var/folders/…) most likely

From either location you can open it with Preview, without creating it a second time. Since it’s trivial to retrieve it from the Downloads folder, I would do that. (See post above.)
This has the additional advantage that you don’t have a Safari tab busy with downloading and displaying the PDF.

I should have said TOC or any of the links that were saved internally with the PDF. Preview tries to go to url's regardless of if it is part of the pdf or not so that isn't lost.

Yes that is it, didn't realize he made a video too.

Thanks for that, it looks like for me it is
/private/var/folders/63/wk_llg2146l_b3w4_wsd85jw0000gq/T/WebKitPDFs-dFx5Ap/rapidweaver_manual_v7.pdf

The PDF's don't actually show up until you right click and open with Preview, though which is interesting. I guess Safari loads them into RAM or something when just loaded into the browser.

I tried this with multiple PDF's and they all show up in there once you open with PDF. It's interesting that even if you give full read and write access to that folder and apply to enclosed contents even after the PDF is sitting open in Preview you still can't command click to get to the file (I don't really need to but found that curious).

So are you doing that somehow with a macro or are you just going to the page and then option clicking on it and then using the other macro to open a file. I wasn't able to get Keyboard Maestro to open the most recent file from the linked forum macro after playing with it a bunch. I deally I don't really want it saved anywhere and really like how I can just close it out when I choose the option open with Preview. Safari handles all that for you in deleting when closed.

For now I at least have this working though not at all elegant or bulletproof. RapidWeaver 7 - Help Manual.kmmacros (33.9 KB)

Interesting, I thought the loaded PDF lands there. So, it either lands in Safari’s cache folder, or in RAM as you say, and gets copied there once you launch Preview from the contextual menu.

No, not Option-clicking on the page, Option-clicking the link.

Yep, but you’re loosing PDF bookmarks (ToC) because you are re-creating the PDF. If you take the original one (which is already downloaded, either in RAM or disk cache, or in the Downloads folder) you won’t loose any PDF features.

“Save as PDF” or “Open PDF in Preview” form the Print menu makes sense if you have other document types, like images or whatever, but it’s superfluous if you already have a PDF.

Right sorry I should have typed option clicking the link on the page. I just wasn't sure if you were somehow automating the option click of a specific link on a page somehow or doing that manually. It would be awesome if when you loaded a PDF into Safari if they then gave you a menu option to "Open in Preview" and not have to deal with the right click stuff.

This path is different for each computer (as is probably expected with a path as crazy as that is) here is the path on another computer to the same file.

/private/var/folders/h1/mmdk_ht16xqgq1p1lnn47bkm0000gq/T/WebKitPDFs-q5Kwzl/rapidweaver_manual_v7.pdf [quote="Tom, post:11, topic:4937"]
(/private/var/folders/…)
[/quote]

I'll have to read up on how the OS chooses the folder path. Perhaps I am revealing some hidden code to my computer by posting the full path here.

Yep, that’s why I proposed to grab it from the Downloads folder. Easier.

And, btw, downloading (Option-click) and then opening the downloaded PDF in Preview (with the help of the folder watch macro) won’t take any longer than waiting for the PDF to load in Safari. (Well, if the PDF is very small it may be 1s faster in Safari :wink:)

Edit:

Here is a page with hundreds of PDFs for testing. For me they open faster with the optionclick-folderwatch-Preview method than they render in Safari.

Very nice thanks. The thing that slows me down is changing my sort order and then navigating to the -Temp PDF folder in the downloads and pressing return to save there. It is the darn user that gets in the way. I usually sort by date added which makes it difficult to find a specific folder.

You don’t have to press Return. Just Option-click (⌥) a download link. You don’t have to move them to the -Temp folder. Let KM or Hazel do that work. The same for adding dates: perfect work for KM or Hazel :wink: