Skip to main content

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!

I've been using this without issue:

 

 

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

 

 

 

 

 


I've been using this without issue:

 

 

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

 

 

 

 

 


That's not supposed to be an Emoji...adding screenshot 


That's not supposed to be an Emoji...adding screenshot 


Commands via Emojis would be "fun"!


@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/

 


Commands via Emojis would be "fun"!


I'm here for it. But I've started to dig into this and will hopefully get this resolved for you all shortly.


@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/

 


Thanks, this was just what I was looking for!


I'm here for it. But I've started to dig into this and will hopefully get this resolved for you all shortly.


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.