Posted on 01-13-2022 10:05 AM
Hi folks, with Python deprecated and throwing scary warnings to users when it's invoked by Jamf, we're looking to replace our trusty logged-in-user detection command that we use in scripts. Self Service scripts work reliably with $3, but what method are you all using to detect the logged-in user for other scripts? What works reliably every time, and doesn't pick up _mbsetupuser or similar accounts?
Thanks in advance for any suggestions!
Solved! Go to Solution.
Posted on 01-13-2022 11:10 AM
@alexjdale Here's @arminBriegel 's pretty much definitive discussion on best practice for determining the logged in user: https://scriptingosx.com/2020/02/getting-the-current-user-in-macos-update/
01-13-2022 10:49 AM - edited 01-13-2022 11:23 AM
I've been using this without issue:
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name 😕 && ! /loginwindow/ { print $3 }' )
01-13-2022 10:50 AM - edited 01-13-2022 10:51 AM
That's not supposed to be an Emoji...adding screenshot
01-13-2022 11:05 AM - edited 01-13-2022 11:06 AM
Commands via Emojis would be "fun"!
Posted on 01-13-2022 12:00 PM
I'm here for it. But I've started to dig into this and will hopefully get this resolved for you all shortly.
Posted on 01-13-2022 12:33 PM
That would be great to get this fixed @CalleyO The forum converting text to emojis really shouldn't happen inside a code block, for obvious reasons.
Posted on 01-13-2022 11:10 AM
@alexjdale Here's @arminBriegel 's pretty much definitive discussion on best practice for determining the logged in user: https://scriptingosx.com/2020/02/getting-the-current-user-in-macos-update/
Posted on 01-13-2022 12:14 PM
Thanks, this was just what I was looking for!