Files
Alte_Skripte/change_username.sh
2026-02-16 15:05:15 +01:00

56 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
##########################################################################
# Shellscript : Script benennt User um (neuer Name )
# Autor : Andreas Vogel, nextenterprise gmbh
##########################################################################
################# function ###############################################
askolddir () {
osascript <<EOF - 2>/dev/null
set strPath to POSIX file "/Users/"
set f to (choose folder with prompt "$1" default location strPath)
set posixF to POSIX path of f
tell application "Finder" to set filesDir to container of f as alias as text
set posixDir to POSIX path of filesDir
posixF
EOF
}
asknewdir () {
osascript <<EOF - 2>/dev/null
tell application "SystemUIServer"
activate
text returned of (display dialog "$1" default answer "Exampel: maxmustermann")
end tell
EOF
}
asknewname () {
osascript <<EOF - 2>/dev/null
tell application "SystemUIServer"
activate
text returned of (display dialog "$1" default answer "Exampel: Max Mustermann")
end tell
EOF
}
################# Variabeln ##############################################
PDIR=$(askolddir 'Please select user') || exit #Pfad zum Homefolder
UDIR=$(echo $PDIR | sed 's/.$//') #Breiningung des Pfad
ONAME=$(echo $UDIR | cut -d'/' -f3-) #Separierung des Username
NNAME=$(asknewname 'Please enter your new name. For example: Mac Mustermann') || exit #legt neuen User & Pfadnamen fest
NDIR=$(asknewdir 'Please enter the new username. For example: maxmustermann') || exit #legt neuen User & Pfadnamen fest
################# execution ##############################################
dscl . change /Users/"$ONAME" RecordName "$ONAME" "$NDIR"
dscl . change /Users/"$ONAME" RealName "$ONAME" "$NNAME"
#Userfolder SymbolicLink anlegen
ln -s /Users/"$ONAME" /Users/"$NDIR"
#Userfolder "verstecken"
chflags hidden "$PDIR"
# Meldung
osascript -e 'tell application "SystemUIServer" to display dialog "Benutzer wurde erfolgreich geändert!" buttons {"OK"} default button "OK"'
exit 0