Force Restart After Inactivity

Contributor III

Hi all,

I have a need for a script that forces Macs to restart after 10 minutes of inactivity. There would need to be a warning that pops up as well, say after 8 minutes of inactivity to give a user a heads up that a restart is coming. Anyone know of such a script or way to provide such a feature that is already in existence?



Contributor III

You may be able to adapt our auto logout daemon; (daemon) (script, there may be an older shell version of the script too) to perform this task... 

Thank you @dsavageED . If you are adding this to Jamf as a script that runs at a Login, how do you get it to trigger on a recurring basis after a user logs in? From looking at the script it looks like it exits if the idle time is detected to be less than 1.

The script as it stands is called by a daemon, both are meant to be locally installed on the system. It isn't something that is easy to do just running off a login hook...

To run from a login hook, you could generate a script and then launch it in the background with a loop that sleeps for 30 mins or something, but in that case you could just run the script at check-in on the Mac. Short answer is I don't think login is the right place to try and run this from.

@dsavageED have you upgraded this script to work with Python 3 in Monterey?  I have attempted to do so, but am having trouble getting Jamf process to quit to allow the logout.

Contributor II

May I know what are you trying to achieve as restarting Mac when it is inactive for 10 minutes will give bad user experience.

Sure @Samstar777 , if you are curious it is for a college library, and is meant to prevent a student walking way while leaving browsers logged into a website, or other personal data on the machine accessible to the next student using the machine.

We aren't currently set up to have our students log into a Mac with their school IDs so, this is an alternative.

Our Macs are frozen with Deep Freeze for Mac, so a restart takes the Mac back to a clean slate.

Our Windows machines do the same thing, but log the student out rather than restart the Mac, as our students do log into these devices.

Contributor II

You may explore below link once