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).