Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Adding and using keyboard shortcuts in the Print dialog box' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Adding and using keyboard shortcuts in the Print dialog box
Authored by: regulus on Jul 24, '09 08:49:12AM
Counting Tabs and "down arrows" is difficult at best and often subject to change as applications are updated and features are added. If you're going to use gui scripting techniques it's best to press things by name instead. Here's what you can use to do pdf stuff in Safari or Firefox. Just fix the first 2 lines of this applescript as you need.
set webBrowser to "Safari" -- or Firefox
set pdfMenuItemTitle to "Save as PDF…" -- the title of the menu item you want
set myDelay to 0.2

tell application webBrowser to activate
tell application "System Events"
	tell process webBrowser
		-- open the print dialog
		click menu item "Print…" of menu 1 of menu bar item "File" of menu bar 1
		delay myDelay
		
		-- open the pdf menu items
		if webBrowser is "Firefox" then
			click menu button "PDF" of window "Print"
		else
			click menu button "PDF" of sheet 1 of window 1
		end if
		delay myDelay
		
		-- click the save-as-pdf menu item
		if webBrowser is "Firefox" then
			click menu item pdfMenuItemTitle of menu 1 of menu button "PDF" of window "Print"
		else
			click menu item pdfMenuItemTitle of menu 1 of menu button "PDF" of sheet 1 of window 1
		end if
		delay myDelay
		
		-- make sure the desktop is the location for the saved pdf
		keystroke "d" using command down
		delay myDelay
		
		-- save the pdf
		click button "Save" of window "Save"
	end tell
end tell


[ Reply to This | # ]