Run script if nobody is logged in

MBrownUoG
Contributor

Hey folks.

This is likely something ridiculously simple to do, but I'm trying to find a way of running a script via Jamf that checks if Mac is sat at a login screen with nobody logged in, and then triggers another policy to run if that's the case.

I have tried a version of the following code (hijacked from an old Jamf thread) which I had assumed would be ok, but doesn't seem to detect when a High Sierra Mac is sat unused:

current=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

if [[ $current != root ]] 
then
    /bin/echo "$current is logged in, exiting script..."
else
    jamf policy -trigger ProgramToBeRun
fi

Am I missing a trick here?

1 REPLY 1

MBrownUoG
Contributor

IGNORE THIS

Literally as I clicked the button to post this, I found a machine that worked using the above code. If I could delete the thread I'd happily do so!