#!/bin/bash ########################################################################## # Shellscript : Script benennt User um (neuer Name ) # Autor : Andreas Vogel, nextenterprise gmbh ########################################################################## ################# function ############################################### askolddir () { osascript </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 </dev/null tell application "SystemUIServer" activate text returned of (display dialog "$1" default answer "Exampel: maxmustermann") end tell EOF } asknewname () { osascript </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