Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Adding printers via script

Due to great support i find my self here again asking more questions because i wanna learn how to write scripts 🙂


So bassically i work between 2 schools (all mac's) and each school has about 20 printers or so i would like to create a script so all i have to do when i want to add a printer is to enter is IP address of the printer, name and location. Im running into the problem after add printer has activated i cant seem to get it too click the ip bar up the top any feed back would be greatly appricated.
My script so far below




set Ip_address to ""

set printer_name to ""

set Location to ""

set dialog_1 to display dialog "Enter Printer Ip Adress" default answer "" buttons {"OK"} default button 1

set dialog_2 to display dialog "Enter Name of Printer" default answer "" buttons {"OK"} default button 1

set dialog_3 to display dialog "Enter Location of Printer" default answer "" buttons {"OK"} default button 1

set Ip_address to the text returned of dialog_1

set printer_name to the text returned of dialog_2

set Location to the text returned of dialog_3


tell application "AddPrinter" to activate

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 "& Ip_address"

MacBook, Mac OS X (10.6.8)

Posted on Mar 28, 2012 8:44 PM

Reply
Question marked as Best reply

Posted on Mar 29, 2012 8:53 AM

On Mac OS X 10.7.3, your last lines of code should be written as follows:


tell application "AddPrinter" to activate

tell application "System Events"

tell process "AddPrinter"

tell window "Add Printer" -- or “window 1”

click button "IP" of tool bar 1 -- or “button 3”

tell combo box 2 of group 2 of group 1

set focused to 1

set value to IP_address

end tell

end tell

end tell

end tell

(I personally use UIElementInspector 1.4 to help me with GUI Scripting.)

6 replies
Question marked as Best reply

Mar 29, 2012 8:53 AM in response to hoarebags

On Mac OS X 10.7.3, your last lines of code should be written as follows:


tell application "AddPrinter" to activate

tell application "System Events"

tell process "AddPrinter"

tell window "Add Printer" -- or “window 1”

click button "IP" of tool bar 1 -- or “button 3”

tell combo box 2 of group 2 of group 1

set focused to 1

set value to IP_address

end tell

end tell

end tell

end tell

(I personally use UIElementInspector 1.4 to help me with GUI Scripting.)

Mar 29, 2012 5:35 PM in response to hoarebags

Have you downloaded UIElementInspector? It's not possible to do any serious GUI Scripting without it (or without a similar tool). So if you haven't yet, go to this web page and click the “Download Sample Code” button at the top of the page. Then open the downloaded UIElementInspector folder. Then move the UIElementInspector.app file to your Applications folder. Then trash the downloaded folder.


UIElementInspector will help you find the answers to the questions you are asking in your last post.

Mar 29, 2012 6:05 PM in response to hoarebags

On Mac OS X 10.7.3 (but probably not on Mac OS X 10.6.8), you would enter IP, name and location as follows:


tell application "AddPrinter" to activate

tell application "System Events"

tell process "AddPrinter"

tell window 1 -- or “window 1”

click button "IP" of tool bar 1 -- or “button 3”

tell combo box 2 of group 2 of group 1

set focused to 1

set value to IP_address

end tell

delay 1

tell group 1 of group 1

set value of text field 1 to printer_name

set value of text field 2 to printer_location

-- you can't use the reserved word “location”

end tell

end tell

end tell

end tell

Adding printers via script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.