Apple Script: Programm opening "Password changing ..."

ds_support
New Contributor III

Hello Community,

I am looking for a solution, to change the user password in the AD and in the Keychain. With the normal "Password chaning" in the System preferences it works. I am write a Apple Script, that opening the "system preferences" -> "Users".

My question is, which command I need to open the "password chaning..." inside the User Settings?

Here is the actuelly script:

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preferences.users"
    reveal anchor "passwordPref" of pane id "com.apple.preferences.users"
    tell application "System Events"
        tell process "System Preferences"

        end tell
    end tell
end tell

I hope everyone can help! :-)

Many Thanks
Christian

8 REPLIES 8

talkingmoose
Moderator
Moderator

I recently assisted a customer with a similar request and developed this AppleScript. It uses System Events to click the Change Password button after opening the Users & Groups pane in System Preferences.

tell application "Finder" to open file "Accounts.prefpane" of (path to system preferences)

tell application "System Events"
    tell application process "System Preferences"
        delay 1
        click button "Change Password…" of tab group 1 of window "Users & Groups"
    end tell
end tell

The ellipsis at the end of the "Change Password…" button name is a true ellipsis ( Option + ; ) not three periods.

ds_support
New Contributor III

Hello @talkingmoose,

Many Thanks for help! The script works great! I needed only to translate the words in german. Because my system works in german...

But it works great!

Maybe you have a idea how we can create one script for Multilanguage? That it works on German, English and more?

Many Thanks!
Christian

talkingmoose
Moderator
Moderator

@c.knipping, the script could probably translate to using numbered identifiers instead of names, but I'd need to see an example in a different language first to know for sure.

ds_support
New Contributor III

@talkingmoose many Thanks for help...

Here ist your script translated in German.

tell application "Finder" to open file "Accounts.prefpane" of (path to system preferences)

tell application "System Events"
    tell application process "Systemeinstellungen"
        delay 1
        click button "Passwort ändern …" of tab group 1 of window "Benutzer & Gruppen"
    end tell
end tell

mm2270
Legendary Contributor III

Just wanted to post here that you can actually use a number for the Change Password button. It turns out its "2", at least in 10.10 and 10.11. You also cannot use "Users and Groups" as the window name since in other languages it doesn't show as "Users & Groups" You can change that to "window 1" though.

I'm not sure about any of this under older OSes and I did not go back to them to test it out. But for recent OSes, the following script actually works, even when under a different language, as long as Applescripts are allowed to do Assistive Access stuff beforehand, otherwise it throws an error.

tell application "Finder" to open file "Accounts.prefpane" of (path to system preferences)

tell application "System Events"
    tell application process "System Preferences"
        delay 1
        click button 2 of tab group 1 of window 1
    end tell
end tell

Hope that helps anyone else running across this.

Josh_Smith
Contributor III

@c.knipping You may be aware of ADPassMon, it's "Behavio[u]r 2" password change functionality is similar to what you are trying to do and written in AppleScript. Just wanted to mention it in case you were not aware. You could use it directly, fork it to suit your needs, or just look at the code to help you work through what you are doing.

fgeronimo
New Contributor

Thank you for sharing this @mm2270. I'm running 10.11.5 and button 2 selected "Open Parental Controls…" for me. I had to use button 3.

tell application "Finder" to open file "Accounts.prefpane" of (path to system preferences) tell application "System Events" tell application process "System Preferences" delay 1 click button 3 of tab group 1 of window 1 end tell end tell

mm2270
Legendary Contributor III

@fgeronimo Hmm, interesting. I'll need to retest that. Maybe I missed something when I checked that on 10.11. I guess if there are changes in the UI for the Users & Groups prefpane then it could click the wrong button like that. Thanks for the heads up on that.