Skip to main content
Solved

Best User-Detection Command for Scripts?


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/

 

View original
Did this topic help you find an answer to your question?

7 replies

ljcacioppo
Forum|alt.badge.img+17
  • Contributor
  • 183 replies
  • 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
  • Contributor
  • 183 replies
  • January 13, 2022
ljcacioppo wrote:

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
  • 59 replies
  • January 13, 2022
ljcacioppo wrote:

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

 


Commands via Emojis would be "fun"!


sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3533 replies
  • 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
  • 141 replies
  • January 13, 2022
awoodbury wrote:

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
  • 881 replies
  • January 13, 2022
sdagley wrote:

@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+16
  • Legendary Contributor
  • 7880 replies
  • January 13, 2022
CalleyO wrote:

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings