Last active
August 2, 2018 13:32
-
-
Save AndrewWCarson/ecb6d0b79dc1a6850213c16fc92aa64e to your computer and use it in GitHub Desktop.
Enables fast user-switching for all macOS user
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 | |
# This script is designed to be run as root from a mgmt system like Addigy. | |
# Change the field separator to newline for usernames with directories | |
OIFS=$IFS | |
IFS=$'\n' | |
# Iterate through all users | |
for user in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do | |
userHome=$(dscl . read /Users/"$user" NFSHomeDirectory | awk '{print $2}') | |
if [ $(defaults read "${userHome}/Library/Preferences/com.apple.systemuiserver.plist" 2> /dev/null | grep -i user.menu) == "" ]; then | |
echo "Applying fast-user settings for user:$user" | |
touch "${userHome}/Library/Preferences/com.apple.systemuiserver.plist" | |
defaults write "${userHome}/Library/Preferences/com.apple.systemuiserver.plist" menuExtras -array-add '<string>/System/Library/CoreServices/Menu Extras/User.menu</string>' | |
fi | |
done | |
# Set the global fast-user setting and reset the System settings to make it | |
# show immediately | |
defaults write /Library/Preferences/.GlobalPreferences MultipleSessionEnabled -bool Yes | |
killall -HUP SystemUIServer | |
# Reset the separator | |
IFS=$OIFS |
Improved looping through users. Line 11 still needs some work. I don't think it works if there are spaces in the home directory. Maybe I just need to push it through a sed that drops the beginning of the line as I believe that is the same every time.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need to improve this with a more robust loop through user directories.