How do we run a command through Jamf as the currently logged in user?

ricardo_achong
New Contributor

How do we run a command through Jamf as the currently logged in user?

2 REPLIES 2

r0blee
New Contributor III

The JAMF binary gets the current user and assigns it to the variable $3 so you could do something like the following:

su $3 -c ‘{command goes inside these quotes}’

Hopefully that helps you.

Rob

mschroder
Valued Contributor

What is in your eyes 'the currently logged in user'? If you want the account used to log in to the Mac, you can use "ls -l /dev/console | awk '/ / { print $3 }'" to get the account. If you want to know the account that was used to login to the Self-Service, you can use "$3" to get the account. In many environments both might be the same, in some environments they can be different. In our place most users use local accounts to log in to their Mac, but Active Directory accounts to log in the Self-Service, so for use "$3" would not work.