1

I frequently save pages as PDF from Chrome on OSX. The page is apple-P then click the PDF button and the "Save as PDF.." menu item. I always use the pre-filled filename and save in the default directory.

Is it possible to save this as an automator script? If that is possible I woulld sure like to add this as a button on Chrome somewhere so I can just "save this for reading later"

Thanks for any help.

2
  • FYI, instapaper.com is an excellent service for saving webpages for offline reading.
    – ghoppe
    Mar 14, 2011 at 16:53
  • Yeah I know of it, but do not want. I want a way of saving a web page as PDF at the moment.
    – dwatson
    Mar 22, 2011 at 0:23

2 Answers 2

2

I only tested this with Safari and Chrome, but see this thread for a more complex script.

delay 0.3 -- time to release modifier keys if the script is run with a shortcut
tell application "System Events" to tell (process 1 where frontmost is true)
    if name is "Google Chrome" then
        keystroke "p" using {option down, command down}
        delay 0.1
        tell menu button 1 of window 1
            click
            click menu item "Save as PDF…" of menu 1
        end tell
        keystroke "l" using {option down, command down}
        keystroke return
    else
        keystroke "p" using command down
        tell menu button 1 of sheet 1 of window 1
            click
            click menu item "Save as PDF…" of menu 1
        end tell
        keystroke "l" using {option down, command down}
        keystroke return
    end if
end tell

You could also use wkpdf, but the page has to be loaded again and it doesn't work with authentication or block ads.

tell application "Google Chrome" to tell active tab of window 1
    set u to URL
    set t to title
end tell
do shell script "wkpdf --source " & quoted form of u & " --output ~/Desktop/" & quoted form of t & ".pdf"

If you assign "Save as PDF..." to ⌘P in System Preferences, you can open the dialog just by pressing PP while holding command (or ⌥⌘P and ⌘P in Chrome).

2
  • This has been working for me with a couple of minor modifications. I used Automator to create a Service with no input and for only Chrome, added a Run AppleScript action, and pasted the above script in as the Applescript text. It worked as is or also within the boilerplated "on run ()" wrapper that Automator provides. I named the new Automator Service "ChromePrintPDF.workflow". I then went to System Preferences > Keyboard > Keyboard shortcuts and added a hotkey for the new service. I used Ctrl+Alt+Opt+P which doesn't conflict with anything pre-defined. It works
    – August
    Mar 8, 2013 at 19:32
  • I had to increase the "delay 0.1" after the keystroke and before the "tell menu button" because I kept getting Automator errors after the window popped up and before it did anything else. I increased the delay to 0.5 and haven't had any more errors. I also increased the initial delay from 0.3 to 0.5 based on the idea that if they original author's system was so much faster than mine in one place, it might be in another too.
    – August
    Mar 8, 2013 at 19:32
0

Use the Service template in Automator. Service receives no input in Google Chrome.app, workflow is Utilities > Watch Me Do, then perform your print action so it can be captured by Automator. (Chrome doesn't provide any Automator actions, but Watch Me Do only requires Universal Access.)

Alternately, you can use AppleScript, but working out exactly how to reference things can be "interesting" and I notice its dictionary doesn't reference the standard print settings type so you may not be able to control the Print dialog.

2
  • How can he record when using the Watch Me Do action explicitly? I only managed to do that with Workflow » Record, creating the Watch Me Do automatically. Also, he needs to be careful how Safari is activated, clicking on the window will associate it by name (Activate Window "google chrome - How to record a..." or something like that), it's safer to click the Dock icon. And I still have a hard time getting it to reproduce -- I guess it doesn't like an auto-hidden Dock or fast mouse movements.
    – Daniel Beck
    Mar 16, 2011 at 6:37
  • that is what I am looking to do! It shows up in the Google Chrome Services menu, however it throws an error when I try and run it; "The Action 'Watch Me Do' had an error" The Watch me do action in Automator says: - Click the "File" menu. - Print... - Save as PDF... - Click the "Save" button PS - I didn't have to add the Watch me do action itself, mearly hit the record button on automator.
    – dwatson
    Mar 22, 2011 at 0:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .