Last active
October 11, 2016 19:53
-
-
Save krispayne/95d66b68a9380ceaa125e0cdd3f037e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Unlock that account, you sly computer | |
# Path to CocoaDialog | |
CD="/Applications/Utilities/cocoaDialog.app/Contents/MacOS/cocoaDialog" | |
# Quick sanity check to make sure cocoaDialog is installed in the path specified | |
if [ ! -e "$CD" ]; then | |
echo "cocoaDialog was not found in the path specified. It may not be installed, or the path is wrong. Exiting..." | |
exit 1 | |
else | |
# If cocoaDialog was found, check to make sure its the 3.0 beta 7 version | |
exePath=$(echo ${CD#$(dirname "$(dirname "$CD")")/}) | |
cDInfoPath="$(echo "$CD" | sed "s|$exePath||")Info.plist" | |
if [[ $(defaults read "$cDInfoPath" CFBundleShortVersionString) != "3.0-beta7" ]]; then | |
echo "The version of cocoaDialog installed is not 3.0-beta 7. The 3.0-beta7 version is required for proper functioning of this script." | |
exit 1 | |
fi | |
fi | |
INPUT=$("${CD}" inputbox --title "Enter username to unlock" --informative-text "Enter username to unlock:" --text "username" --float --button1 "Unlock" ) | |
LOCKEDUSERNAME=$(echo "${INPUT}" | awk -F":" '!/1/{ print $1 }') | |
# Read the failed attempts and timestamp, for posterity | |
FAILCOUNT=$(dscl . readpl /Users/${LOCKEDUSERNAME} accountPolicyData failedLoginCount | awk '{ print $2 }') | |
FAILTIME=$(dscl . readpl /Users/${LOCKEDUSERNAME} accountPolicyData failedLoginTimestamp | awk '{ print $2 }') | |
# Reset the count | |
if [[ ${FAILCOUNT} -ge 1 ]]; then | |
echo "User \"${LOCKEDUSERNAME}\" has failed at some point." | |
echo "Reset their failures..." | |
dscl . createpl /Users/${LOCKEDUSERNAME} accountPolicyData failedLoginCount 0 | |
echo "Reset the failed timestamp..." | |
dscl . createpl /Users/${LOCKEDUSERNAME} accountPolicyData failedLoginTimestamp 0 | |
INEEDTOBEREMINDED=$("${CD}" msgbox --title "Restart the computer" --text "Please restart the computer, now." --float --button1 "OK") | |
else | |
echo "I'm sorry, but user \"${LOCKEDUSERNAME}\" doesn't appear to have any issues." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment