How to get current loggedin user on Mac via script


I won't waste time wiring details. This works as of today, but what will Apple do in future, only God knows. 
🤓 It's always suggested to run the command without variable to ensure it work, but you probably know that. 

CurrUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')

Comments