Since I have been on Lion something has been irritating me: I lost the keyboard shortcut cmd-alt P that existed in Snow Leopard to print directly the selected pages in Preview . This morning I decided to tackle the subject as every saturday morning I have to print some pages from a long pdf file.
After some trial and errors, I managed it and would like to share it by posting it in case someone needs it.
“Before writing code that makes use of UI Scripting in Mac OS X, you will first need to manually configure the machine on which the script will run, so that it can respond to UI Scripting commands. To enable UI Scripting, launch the System Preferences application, and click on the Universal Access button. Next, enable the checkbox labeled Enable access for assistive devices” (http://www.mactech.com/articles/mactech/Vol.21/21.06/UserInterfaceScripting/index.html)
Type the following script in Applescript Editor.
tell application "System Events"
tell process "Preview"
set frontmost to true
click menu item "Print." of menu "File" of menu bar 1
repeat until sheet 1 of window 1 exists
end repeat
tell sheet 1 of window 1
tell radio group 4
tell radio button 3
click
end tell
delay 0.5
end tell
click button "Print"
end tell
end tell
end tell
Save it in /Users/YourHouse/Library/Scripts that you can open via the Applescript menu in the top menu bar.
I use FastScript http://www.red-sweater.com/fastscripts/ to associate a cmd-alt-P to the script et voilà ! it works.
(If you are french like me you have to replace “Print” by “Imprimer” and “File” by “Fichier” in the script.°
Model: iMac 21.5-inch, Mid 2011
AppleScript: 2.2.1
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)