How to use Applescript to open a printer app and select items within

applescriptautomatorcanonprinting

I have absolutely no knowledge or experience in using Applescript or Automator. I'm hoping by using either to create an app (or script) that will print a test page off my printer automatically. I know how to open the printer app (Canon iX6800 series.app), but I'm stuck from there with the dialog box not knowing how to continue to do the following steps:

  1. Run "Canon iX6800 series" – I got this part…
  2. Select "Settings" or Command S
  3. Select "Utility"
  4. Select "Print Test Page"
  5. Click "OK"
  6. Quit the app.

Any suggestions or help will be greatly appreciated. I can send the actual app to whoever might need it. Thanks in advance.
George

Best Answer

I believe I've roughly translated your steps into a working AppleScript:

tell application "Canon iX6800 series" to activate -- Run "Canon iX6800 series"
delay 0.25
tell application "System Events" to tell process "Canon iX6800 series"
    click menu item "Canon iX6800 series" of menu "Window" of menu bar 1
    click menu item "Settings" of menu "Printer" of menu bar 1 -- Select "Settings"
    click radio button "Utility" of tab group 1 of sheet 1 of window 1 -- Select "Utility"
    click button "Print Test Page" of tab group 1 of sheet 1 of window 1 -- Select "Print Test Page"
    key code 53 -- escape key (selects Cancel)
end tell
tell application "Canon iX6800 series" to quit -- Quit the app

Note that the part at the beginning (with the delay and window selection) is necessary to ensure that an active window is open in the printer app; otherwise, the Settings panel won't be able to open if a window isn't already open.


Although the following isn't what the OP is asking for, in case anybody else is looking to do this with a printer that doesn't supply a "Print Test Page" option in the Settings panel, here's an alternate solution:

  1. Open the "Canon iX6800 series" app
  2. Click the "Print Test Page" menu item in the "Printer" menu
  3. Quit the app

To accomplish this, replace lines 5–7 of the above with click menu item "Print Test Page" of menu "Printer" of menu bar 1.