Applescript to fill in Keychain dialog box I'd like to fill in the Keychain Dialog box with the Name: and Password fields (printer is windows print queue), but after the Print command, the Keychain dialog box opens up, but never responds to anything till I click OK or cancel. 

  tell application "TextEdit"
  activate
  make new document

  print document 1 with properties {target printer:"2nd-floor"}

  tell application "System Events"

         set value of text field 1 of group 1 of window 1 to "CUA\name"

         click button 2 of window 1 of application process "SecurityAgent"

  end tell
  end tell


Hope I missing something silly, thanks.
Consider altering the requirement for a password. Printers on Mac OS X are managed by the Common UNIX Printing System (CUPS) and it is highly configurable.

Mac OS X Hints published this, Disable printer queue password requirements, for disabling printer queue passwords. It should work for modern versions of OS X:


  
  As root, or in a Terminal session with su privileges, edit /etc/cups/cupsd.conf.
  Find the section below.
  Remove the items you don't want limited: Pause-Printer, Resume-Printer, Pause-Printer-After-Current-Job, etc.
  Save the file, quit the editor, and restart your computer
  


Section to find and edit:

  &lt;Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Res
tart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Accept-Jobs CUPS-Reject-Jobs&gt;
      AuthType Default
      Require user @AUTHKEY(system.print.admin) @admin @lpadmin
      Order deny,allow
  &lt;/Limit&gt;