Skip to main content
Answer

Best User-Detection Command for Scripts?

  • January 13, 2022
  • 7 replies
  • 54 views

Forum|alt.badge.img+17

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!

Best answer by sdagley

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

 

7 replies

ljcacioppo
Forum|alt.badge.img+17
  • Jamf Heroes
  • January 13, 2022

I've been using this without issue:

 

 

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

 

 

 

 

 


ljcacioppo
Forum|alt.badge.img+17
  • Jamf Heroes
  • January 13, 2022

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 


Forum|alt.badge.img+11
  • Employee
  • January 13, 2022

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


Commands via Emojis would be "fun"!


sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • Answer
  • January 13, 2022

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

 


CalleyO
Forum|alt.badge.img+15
  • Employee
  • January 13, 2022

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.


Forum|alt.badge.img+17
  • Author
  • Contributor
  • January 13, 2022

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


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • January 13, 2022

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.