Apologies in advance if this has been posted in the incorrect place - I’m new.
I am new to Applescript and have been trying to write a script that will automate adding a windows printer. I’ve found the only way to get to the detailed level that I require is to use a UI script (I could be wrong about that).
The script I have partially written/borrowed from the web mostly works but there are a couple of problems with it.
- The first time you run it, it fails, but if you run it again with the addprinter dialogue box already open it works. :o/ I can’t work out the reason for the initial fail.
- If the Advance button has not already been added to the addprinter window (using customize toolbar) then the script fails. I’m having great difficulty trying to work out how I can script the addition of the button if it doesn’t exist.
Heres what I have got so far…
tell application "AddPrinter" to activate tell application "System Events" to tell process "AddPrinter" tell toolbar 1 tell menu 1 tell menu item "Customize Toolbar." --This bit to add the Advanced button but doesn't appear to work. end tell end tell end tell click button "Advanced" of toolbar 1 of window 1 tell group 1 of window 1 tell group 2 repeat until pop up button 1 exists -- searching for printers may well take several seconds end repeat click pop up button 1 click menu item "Windows printer via spoolss" of menu 1 of pop up button 1 delay 2 set value of text field 1 to "smb://PRINTSERVER" delay 1 end tell tell group 1 set value of text field 1 to "PRINTER" click pop up button 1 click menu item "Select Software." of menu 1 of pop up button 1 delay 2 set uiScript to keystroke "PRINTDRIVER" key code 48 key code 125 delay 2 key code 36 end tell end tell delay 2 tell window 1 click button "Add" end tell delay 3 key code 36 tell group 1 of group 1 of sheet 1 of window 1 --UI elements of pop up button 1 tell pop up button 1 click tell menu 1 -- key presses to select menu items for the prefrecnces as I couldn't get it to work any other way. click menu item "5 paper trays installed" key code 48 key code 48 key code 125 key code 125 key code 125 key code 36 key code 36 end tell end tell end tell end tell --tell application "AddPrinter" to quit
Really hope that all makes sense. Any help/advice would be much appreciated.
Browser: Firefox 32.0
Operating System: Mac OS X (10.8)