Get Logged In Local User with Script

healthcareaa
New Contributor III

I am writing a quick script to delete a file from our users computers. We have Jamf Connect on all computers currently.

I'm using this script to get the logged in user:

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

This used to work for us but now that we are on Jamf Connect it just shows the IDP user, not the local user. I need the local user in the variable because that is actually where Documents are stored for the user.

Any way to extract the actual Local account that the user is logged into and avoid the IDP user?

1 ACCEPTED SOLUTION

jamf-42
Valued Contributor II

Yes... that was more to test the result returned is what you were after.. I use this in JAMF scripts.. and it works?

localuser$(/usr/bin/stat -f%Su /dev/console)

View solution in original post

5 REPLIES 5

jamf-42
Valued Contributor II

does this work? 

/usr/bin/stat -f%Su

healthcareaa
New Contributor III

Not through Jamf because Jamf runs as root

jamf-42
Valued Contributor II

Yes... that was more to test the result returned is what you were after.. I use this in JAMF scripts.. and it works?

localuser$(/usr/bin/stat -f%Su /dev/console)

healthcareaa
New Contributor III

This worked, thank you!

Thank you, it worked for me too.