Hello all,
I am new here and I read the intro post, so i think I am posting in the right place. If not, please forgive me and direct me to the correct location.
I work at a civilian government agency. We have about 500 macs that need a single (poster) printer added to them as an IP printer. For varius reasons this has to be done from each indavidual desktop, instead of remotely by administrator (silly but thats politics). I wanted a script or applet that I could stick on my thumb drive and simply double click when I get to each desk. I found that someone had started a script and posted it online. I grabbed it and continued working with it, but am stuck in getting it to choose the printer type. Am I going about this the wrong way? any ideas on getting this to work? Right now I am trying to have it enter an ‘h’ and it tells me it does not understand the command. I am not a scripter by training or nature.
here is ‘my’ script:
activate application "Printer Setup Utility"
tell application "System Events"
launch
tell process "Printer Setup Utility"
click menu item "Add Printer." of menu 1 of menu bar item "Printers" of menu bar 1
tell window "Printer Browser"
click button "IP Printer" of tool bar 1
set value of combo box 1 of group 1 of group 1 of group 2 of group 1 to "37lpd.xxx.xxx.gov"
set value of combo box 2 of group 1 of group 1 of group 2 of group 1 to "37posterprinter"
set value of combo box 3 of group 1 of group 1 of group 2 of group 1 to
delay 2
keystroke tab & tab & tab & h & tab
end tell
end tell
end tell
activate application "Printer Setup Utility"
tell application "System Events"
launch
tell process "Printer Setup Utility"
click menu item "Add Printer." of menu 1 of menu bar item "Printers" of menu bar 1
tell window "Printer Browser"
click button "IP Printer" of tool bar 1
tell combo box 1 of group 1 of group 1 of group 2 of group 1 to set value to "127.0.0.1"
keystroke tab & tab & tab & return
click button "Add"
end tell
end tell
--quit
end tell
--quit application "Printer Setup Utility"
Bruce, your script looks like the one I started with, so THANK YOU!
Jacques, you cleared up a number of issues for me.
I had, before i saw your replies, found the UI Browser app which is absolutely fantastic and I suggest it to everyone.
with that, i made the following script (which i will be amending with items from Jacques’s script):
activate application "Printer Setup Utility"
tell application "System Events"
launch
tell process "Printer Setup Utility"
click menu item "Add Printer." of menu 1 of menu bar item "Printers" of menu bar 1
tell window "Printer Browser"
click button "IP Printer" of tool bar 1
set value of combo box 1 of group 1 of group 1 of group 2 of group 1 to "37lpd.nci.nih.gov"
set value of combo box 2 of group 1 of group 1 of group 2 of group 1 to "37posterprinter"
set value of text field 1 of group 1 of group 1 to "37PosterPrinter"
click pop up button 1 of group 1 of group 1
delay 1
select menu item "HP" of menu 1 of pop up button 1 of group 1 of group 1
click menu item "HP" of menu 1 of pop up button 1 of group 1 of group 1
delay 1
select row 26 of table 1 of scroll area 1 of group 1 of group 1
click button "Add"
delay 1
click pop up button 1 of group 1 of group 1 of group 1 of group 1 of sheet 1
click menu item "128 MB Total Memory" of menu 1 of pop up button 1 of group 1 of group 1 of group 1 of group 1 of sheet 1
delay 1
click button "Continue" of group 1 of group 1 of sheet 1
end tell
end tell
My final script deals with the issues of the specific model setup, but i chose the specific printer model in a fashon that is almost garaunteed to cause issues… i did it by item number in the table, and realized as soon as I saw your script that it was an issue.
THANK YOU BOTH.
as soon as I have this fully tested i will post it back, with both your names as author.
I am still working on figuing out how to enable the GUI scripting (ie turn on ‘enable access for assistive devices’) from a script…
here is my ‘final’ IP Printer setup script, written for the most part by other people, with the use of UI Browser, you will notice that soem of the choices I made are a little peculiar, but that is because of the environment I work in. Enjoy:
activate application "Printer Setup Utility"
tell application "System Events"
launch
tell process "Printer Setup Utility"
click menu item "Add Printer." of menu 1 of menu bar item "Printers" of menu bar 1
tell window "Printer Browser"
click button "IP Printer" of tool bar 1
set value of combo box 1 of group 1 of group 1 of group 2 of group 1 to "37lpd.xxx.xxx.gov"
set value of combo box 2 of group 1 of group 1 of group 2 of group 1 to "37posterprinter"
set value of text field 1 of group 1 of group 1 to "37PosterPrinter"
click pop up button 1 of group 1 of group 1
delay 1
select menu item "HP" of menu 1 of pop up button 1 of group 1 of group 1
click menu item "HP" of menu 1 of pop up button 1 of group 1 of group 1
delay 1
select (rows of table 1 of scroll area 1 of group 1 of group 1 whose value of static text 1 contains "HP DesignJet 1055CM")
click button "Add"
delay 1
click pop up button 1 of group 1 of group 1 of group 1 of group 1 of sheet 1
click menu item "128 MB Total Memory" of menu 1 of pop up button 1 of group 1 of group 1 of group 1 of group 1 of sheet 1
delay 1
click button "Continue" of group 1 of group 1 of sheet 1
end tell
end tell
end tell
I too had a need to create printers via a script, as I am in charge of creating new OS X builds for my company. Not only was it tedious entering all our printer queues by hand, but I always ran the risk of human error creeping in and spoiling the build.
So it was with glee that I found this thread. I adapted the shared scripts to our printers (with great help from Prefab UI Browser) and soon had a script that in mere minutes created all our print queues in my Tiger builds.
Except the queues didn’t work. They looked OK; all the data was good, but users could not print. Print jobs constantly failed and the queues put themselves on hold. Re-entering the exact same data by hand resulted in a completely functional queue–only the script-created ones failed.
Upon closer examination, it seems that Apple has engineered an on-the-fly validation checker on the Address field. This how they present the “Valid and complete address” subtext as users enter the server address. And I think this is why queues do not work unless text is typed into the field; you can’t just populate the Address or the checker never runs. Without the checker, the resulting printer queue is DOA.
Therefore I’ve modified the scripts so that they do not fill the field using “set value”, but instead use the keystroke command to make the print manager think I’m typing in the values. This works… albeit with some trickery.
Attempts to elegantly highlight the Address field failed (as you can see from the comments in the script). So I used tabs, but found that if “IP Printer” is already highlighted, the print manager requires a random number of tabs to highlight the Address field. This is why I have the script first select “Default Printer” and then (re)select “IP Printer”; to reset the tab position. It’s a kludge to be sure, but it works. I’m also not sure if all the delays are necessary, but since we’re typing into the GUI I feel a lot more secure giving the GUI a chance to keep pace. Your mileage may vary.
Hope this helps!
tell application "System Events"
launch
tell process "Printer Setup Utility"
click menu item "Add Printer." of menu 1 of menu bar item "Printers" of menu bar 1
tell window "Printer Browser"
click button "Default Browser" of tool bar 1
delay 1
click button "IP Printer" of tool bar 1
delay 1
-- was: set value of combo box 1 of group 1 of group 1 of group 2 of group 1 to "hp014.mycompany.com"
-- unsuccessfully tried: set first responder of window 1 to combo box 1 of group 1 of group 1 of group 2 of group 1
-- unsuccessfully tried: click combo box 1 of group 1 of group 1 of group 2 of group 1
keystroke tab & tab & tab & tab
delay 1
keystroke "hp014.mycompany.com" & tab
delay 1
keystroke "npi2a0f04" & tab
delay 1
keystroke "Marketing HP 4050" & tab
delay 1
keystroke "3rd floor, cube 17" & tab
delay 1
click pop up button 1 of group 1 of group 1
delay 1
select menu item "HP" of menu 1 of pop up button 1 of group 1 of group 1
click menu item "HP" of menu 1 of pop up button 1 of group 1 of group 1
delay 1
select (rows of table 1 of scroll area 1 of group 1 of group 1 whose value of static text 1 contains "HP LaserJet 4050 Series")
delay 1
click button "Add"
delay 1
click pop up button 3 of group 1 of group 1 of group 1 of group 1 of sheet 1
click menu item "20 - 27 MB" of menu 1 of pop up button 3 of group 1 of group 1 of group 1 of group 1 of sheet 1
delay 1
click button "Continue" of group 1 of group 1 of sheet 1
end tell
end tell
end tell
This is exactly what I have been looking for but it needs to work with El Capitan. I dowloaded UI Browser to familiarize with the program. I have no experience GUI scripting. Got stock in the part where I can type the Name of the printer & select the PPD. Below is the code.
set sysVersion to system attribute "sysv"
if sysVersion is greater than or equal to 4144 then -- 4144 is Mac OS X 10.3.0 Panther
activate application "AddPrinter"
tell application "System Events"
set GUIScriptingEnabled to UI elements enabled
if GUIScriptingEnabled then
tell application process "AddPrinter"
-- insert GUI Scripting statements here:
click button "IP" of toolbar 1 of window "Add "
-- Address:
select text field 1 of group 1 of group 1 of window "Add "
set value of text field 1 of group 1 of group 1 of window "Add " to "10.20.27.XXX"
--I added a delay because I noticed the computer takes some time to gather the information to be populated in the Name: & Use: fields
delay 10
--Name: of the printer if I dont type NP 307 in Indesign is going to show the IP address instead of the printer name
select text field 1 of group 2 of group 1 of window "Add "
set value of text field 1 of group 2 of group 1 of window "Add " to "NP 307"
--Use: to get the printer PPD select drop down menu & choose Select Software.... this will open the Printer software window in which you can choose the PPD in this case Xerox WorkCentre 7120, 3.5.1
click pop up button 1 of group 2 of group 1 of window "Add "
select text field 1 of row 1 of table 1 of scroll area 1 of window "Printer Software"
end tell
end if
end tell
--++++++++++++++++++++++++
if not GUIScriptingEnabled then
beep
if sysVersion is less than 4240 then -- 4240 is OS X 10.9.0 Mavericks
activate
display dialog "GUI Scripting is not enabled" & return & return & "Select the \"Enable access for assistive devices\" setting in Accessibility (or Universal Access) preferences and run this script again." buttons {"Open System Preferences", "Cancel"} default button "Cancel"
if button returned of result is "Open System Preferences" then
tell application "System Preferences"
set current pane to pane "com.apple.preference.universalaccess"
activate
end tell
end if
else
set scriptRunner to name of current application
activate
display alert "GUI Scripting is not enabled for " & scriptRunner & "." message "Open System Preferences, unlock the Security & Privacy preference, select " & scriptRunner & " in the Privacy Pane's Accessibility list, and then run this script again." buttons {"Open System Preferences", "Cancel"} default button "Cancel"
if button returned of result is "Open System Preferences" then
tell application "System Preferences"
tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
activate
end tell
end if
end if
end if
else
beep
display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
end if
Model: iMac
AppleScript: Version 2.7 (176)
Browser: Safari 600.8.9
Operating System: Mac OS X (10.10)