How to set Destination Folder from Safari "Print" and/or Save As PDF?

I want to download statements/bills and save them as PDFs via Safari. I have gotten up to the point where they ask me for the file name, and I can put that in trying both “Print” (and changing printer to PDF) or Save As PDF. However, I can’t figure out how to change the target folder where it will go to. After a bit of experimenting I see that it will default to wherever I was last, not just to say “Downloads”, so I can’t rely on it being downloaded to a certain place and then just moving the downloaded file to where I want it to end up.

I tried to record setting the target folder with the mouse, but instead of saying I clicked on say, Documents, then AmEx, then opened that to get to my AmEx 2015 sub-folder, it is just giving me mouse locations. That isn’t really satisfactory as the screen size may change and, of course, next year I’ll have a different sub-folder which will be at a different location on the screen.

I was also thinking of trying to put the full path into the file name, but that didn’t seem to work either.

Any help would be greatly appreciated.

Thanks,

Stuart

Stuart, you can use keyboard shortcuts normally associated with the Finder, even within the save dialog. As an example Command-Shift-O will bring you to the Documents folder. Command-Shift-D to the Desktop and Command-Option-L for Downloads.

Though I am all for using Keyboard Maestro for stuff like this, I must say I am doing the same type of thing you are and was pointed to a product called Hazel. You could use Keyboard Maestro for the automated download but then have Hazel watch your downloads folder for new files. It can recognize searchable pdf documents, identify what bank statement it is, file it in folders and even create new folders if they are not there. As an example if your bank statement is for July 2015 it can recognize that and create/put it in the 2015 folder. It can rename the file and a whole lot more.

I use Keyboard Maestro for a lot of stuff and am in it daily. Hazel I configure for watching my download folder and let it do it’s stuff. I don’t go into Hazel often as it just does the few things I ask it to very well.

Thanks! I didn’t know about those key short cuts. I’ll look into doing the Command-Option-L to switch from downloads. From there I’m 99% sure I can then move and rename the file with KM.

You can specify the full path folder and file name for the file to be saved from the Command-Shift-G prompt in the Save As dialog.

So the sequence is simply:

  • Command-Shift-G
  • ~/Documents/myfile.pdf
  • Return
  • Return

You may need to allow pauses for the animations of the sheets opening and closing.

2 Likes

Hey Folks,

There's a much better way to go about this.

PDF Service Template.zip (1.1 KB)

Goes here:

~/Library/PDF Services/My Test Ouput Folder

It's just a simple Bash script marked as executable, and you can edit it with any plain-text editor.

Change the name of the file as desired.

Change this line at the top to the path of the folder you want to print your PDF to:

OUTDIR="$HOME/Downloads/My Test Output Folder"

This is what I did with Web Receipts:

You can assign it a keyboard shortcut using System Preferences > Keyboard > Shortcuts > App Shortcuts > All applications.

I gave it an odd-ball keyboard shortcut I am unlikely to use anywhere else.

Then I have an extremely simple macro to open the Print dialog, wait for it to be open, and then press that keyboard shortcut.

Print { PDF to Web-Receipts dir }.kmmacros (2.8 KB)

I've tried a number of methods to do this using Keyboard Maestro and AppleScript & System Events, but this one has turned out to be the fastest and most reliable.

-Chris

3 Likes

Slight edit in the above post.   -ccs

Even better! I just researched Mac keyboard shortcuts and I found both “Open a Go to Folder window” and “Find the next occurrence of the item previously found. To find the previous occurrence, press Command-Shift-G”. I wouldn’t have realized it would have done what we want in Save As dialog, and I even do a bunch of VB and VBA coding.

Thanks again!!

Stuart

Well, this is a dumb newbie question. I trying to get Safari to print a PDF to a bibliography program called Papers. The command should be “File Print PDF Save PDF to Papers” If I could find a script for “Save PRF to DevonThink Pro,” then I could just substitute the program name. The Evernote option above seems to rely on tabbing to the “PDF” option in print and then going down the list tot he Evernote option. However, I can’t figure out how to to from Print to PDF. Any help would be most appreciated. Larry

My macro for Saving PDF to Devonthink is attached - I would think if you change the Insert Text step to “Save PDF to Papers” you’d have what you need.

D - Print to DTP
Triggered by any of the following:
The Hot Key ⌃⌥⇧⌘P is pressed
Will execute the following actions:
Type the ⌘P Keystroke
Pause Until All Conditions Met
Button with name ‘Print’ is enabled
Press Button ‘PDF’
Stop macro and notify on failure.
Insert Text by Typing
Save PDF to DEV
Type the Return Keystroke

Many thanks!
Larry

Hey Chris,

This looks really great!

Is there a way to setup this service so you can pass the output folder and file name as KM Variables?

Thanks.

Hey JM,

It's pretty spiffy. I use it almost daily to print receipts and various other things to specified locations.

One keystroke and done in Safari or Mail.

As far as I know there is no way to set a global-context environment variable from Keyboard Maestro, so you'd have to either use AppleScript or read and write variables to and from a file.

Here's how to use AppleScript from within the shell script:

#!/usr/bin/env bash

read -r -d '' asCMD <<'EOF'
   tell application "Keyboard Maestro Engine"
      set outPutDir to getvariable "outPutDir"
      return outPutDir
   end tell
EOF
OUTDIR=$(osascript -e "$asCMD");

echo "$OUTDIR";

-Chris

1 Like

Hello everybody.

I was trying to record a safari-routine in which I choose CMD P -> Click PDF -> Click “Save PDF to DEVONthink Pro” -> Click OK

The macro stops at PDF and states: Macro Cancelled: Select Menu Item failed because the menu item Ablage>Drucken … is enabled (File>Print)

Any hints, what went wrong here?

Best, Matze

1 Like

I am very late in seeing any of this thread, but there’s a sort of cheat that it looks like many people don’t know about which will likely help folks.

If the user puts an alias in ~/Library/PDF Services to a folder, volume, or application capable of accepting PDFs, then there will be a menu item in the Print dialog under the PDF submenu. Whatever the alias is named will become the name of the menu item. That’s helpful, but there are more ways of utilizing this.

Assume an alias to DEVONThink was created, and it was named Add PDF to DEVONThink. In System Preferences > Keyboard > Shortcuts, adding a shortcut under App Shortcuts > All Applications gives this user-created PDF menu item a system-wide keyboard shortcut.

Now for Keyboard Maestro. Create a macro which invokes the Print menu item, then maybe add a step for a brief pause to allow for the Print dialog to appear, then have Keyboard Maestro simulate the keyboard shortcut for Add PDF to DEVONThink.

Hello NaOH,

I have tried the shortcut solution earlier and it didn’t work.
But your post helped anyway.
If you record CMD-P and then CMD-ALT-^-P for Save PDF to DEVONthink PRO the macro comes up with three Actions.
Type the CMD-P Keystroke
Select Print in the Menu File
Type the CMD-ALT-^-P Keystroke

This macro doesn’t work and stops with the reported error. Even if I enter a Pause in front of it.
But if you delete the second action, then it works!

Thanks! Matze

I just tried the solution as posted by Noah (alias in ~/Library/PDF Services, then System Preferences > Keyboard > Shortcuts) and it works perfectly. (I didn't try it with Devon but with another PDF-capable app.)

To make the shortcut work you have to be in the Print menu of course.

So…

  • is the alias you have created working?
  • when creating the shortcut in System Preferences > Keyboard > Shortcuts have you correctly spelled the name of the menu item?

And it also works perfectly in conjunction with the KM macro as posted above by Chris. (In the macro you have to adapt the Simulated Keystroke and – if you are using a non-English system – the name of the Print button.)

Yes, yes, Tom, it works. It just does not work, when you record the routine of Print and Save to, cos KM places another action to the macro (as explained earlier)

Ah, you mean that Record button of the KM Editor. I don’t think you can create really usable macros with that. (It may be useful to get a first skeleton for a future macro.)

For a newbie like me it works quite well :wink:

@Matze, recording a macro may offer a good starting point, but you should keep in mind that any macro hotkeys you use while recording probably won’t work as expected.

After a bit of experience, I’d suggest that you try creating a macro from scratch (or from one posted in the forum).

1 Like