I have an AppleScript that addresses issues with out-of-sync Active Directory passwords. It resets the secure token on an out-of-sync account by disabling and then re-enabling the token. I run it as a Self Service item but the problem is that once the script has finished, it loops back to the beginning and starts to run again. Not sure why it doesn't quit after the token has been re-enabled. If I run it in Script Editor, it doesn't loop, but from Self Service, it loops back to the beginning after the second verification. Thanks for any help with this one.
set the_folder to (path to users folder)
tell application "Finder"
set foldernames to name of every folder of the_folder
end tell
set theChosenOne to choose from list foldernames with prompt "Select user needing a password sync"
display dialog "Password for " & theChosenOne default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue" with hidden answer
set thePassword to quoted form of text returned of the result
--disable secure token
do shell script "sysadminctl interactive -secureTokenOff " & theChosenOne & " -password " & thePassword
set theVerification to do shell script "sysadminctl interactive -secureTokenStatus " & theChosenOne & " 2>&1 | awk -F']' '{print $2}'"
display dialog theVerification
set the_folder to (path to users folder)
tell application "Finder"
set foldernames to name of every folder of the_folder
end tell
set theChosenOne to choose from list foldernames with prompt "Re-select user needing a password sync"
display dialog "Password for " & theChosenOne default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue" with hidden answer
set thePassword to quoted form of text returned of the result
--re-enable secure token
do shell script "sysadminctl interactive -secureTokenOn " & theChosenOne & " -password " & thePassword
set theVerification to do shell script "sysadminctl interactive -secureTokenStatus " & theChosenOne & " 2>&1 | awk -F']' '{print $2}'"
display dialog theVerification
return