Help Topics
User Accounts Additional Help
|
NISSetup /
ScptThe following script uses UI events to to click through dialog boxes and enter server information in the Directory Utility. This script requires that a key (named "sysPrefsUnlock") is added to the "login" keyring so that system preferences can be unlocked without entering a password or storing the password in the script. It's also important to note that the "login" keychain must be unlocked when the script runs, otherwise it will give a password prompt. The script does not update /etc/hosts. To add the "sysPrefsUnlock" key to the keychain: 1. Open Keychain Access (can be found using Finder) 2. Click the "login" keychain on the left under "Keychains" 3. Unlock the keychain 4. Hit the little '+' sign at the bottom of the window 5. Name the Keychain Item Name "sysPrefsUnlock", Account Name "labstaff", and use the labstaff login/Deepfreeze password for the password 6. Click add 7. Leave the "login" keychain unlocked The script: set pass to getPW() set unlocked to 0 on getPW() do shell script "security 2>&1 >/dev/null find-generic-password -gl \"sysPrefsUnlock\"" return (text 12 thru 18 of result) end getPW (* tell application "System Preferences" activate reveal pane id "com.apple.preferences.users" end tell *) activate application "Directory Utility" tell application "System Events" tell process "Directory Utility" if title of button 3 of group 1 of window 1 is "Click the lock to make changes." then click button 3 of group 1 of window 1 else set unlocked to 1 end if --click button "Search Policy" of tool bar 1 of window "Directory Utility end tell if unlocked is 0 then tell process "SecurityAgent" set value of text field 2 of scroll area 1 of group 1 of window 1 to pass click button 2 of group 2 of window 1 end tell end if tell process "Directory Utility" select row 3 of table 1 of scroll area 1 of group 1 of group 1 of window 1 click button 1 of group 1 of group 1 of window 1 set value of text field 1 of sheet 1 of window 1 to "ececis-academic.udel.edu" set value of text area 1 of scroll area 1 of sheet 1 of window 1 to "devil-rays.acad.ece.udel.edu ns1.acad.ece.udel.edu ns2.acad.ece.udel.edu" click button 1 of sheet 1 of window 1 select row 3 of table 1 of scroll area 1 of group 1 of group 1 of window 1 click button 1 of group 1 of group 1 of window 1 tell checkbox 1 of sheet 1 of window 1 to if value is 0 then click end if click button 1 of sheet 1 of window 1 --update contacts in search policy (NOTE: will probably result in an error if entries already exist) click button 2 of tool bar 1 of window 1 click radio button "Contacts" of tab group 1 of group 1 of group 1 of window 1 click pop up button 1 of group 1 of tab group 1 of group 1 of group 1 of window 1 click menu item 3 of menu 1 of pop up button 1 of group 1 of tab group 1 of group 1 of group 1 of window 1 --add /NIS/ececis-academic.udel.edu as first directory domain click button 2 of tab group 1 of group 1 of group 1 of window 1 select row 2 of table 1 of scroll area 1 of sheet 1 of window 1 click button 2 of sheet 1 of window 1 --add /Local/Default as second directory domain click button 2 of tab group 1 of group 1 of group 1 of window 1 select row 1 of table 1 of scroll area 1 of sheet 1 of window 1 click button 2 of sheet 1 of window 1 --save changes click button "Apply" of group 1 of window 1 if title of button 3 of group 1 of window 1 is "Click the lock to prevent further changes." then click button 3 of group 1 of window 1 end if end tell end tell (* --use this to find ui element numbers --most effective when used with UIElementInspector (https://developer.apple.com/library/mac/samplecode/UIElementInspector/Introduction/Intro.html#//apple_ref/doc/uid/DTS10000728-Intro-DontLinkElementID_2) tell application "System Events" to tell process "Directory Utility" class of UI element of window 1 --class of UI elements of group 1 of window 1 -- etc end tell *) (* IGNORE THIS COMMENT BLOCK tell application "System Events" if title of button 4 of window 1 of process "System Preferences" is "Click the lock to make changes." then click button "Click the lock to make changes." of window 1 of process "System Preferences" --delay 5 tell process "SecurityAgent" set value of text field 2 of scroll area 1 of group 1 of window 1 to pass click button 2 of group 2 of window 1 end tell end if tell application "System Preferences" to activate (reveal anchor "loginOptionsPref" of pane id "com.apple.preferences.users") end tell *) |