Skip to main content

Hey,

I’ve tried looking for this all over and found some partial solutions that don’t really work so I wanted to ask here.

I’ve been asked to set up several iMacs to auto-log off or reboot after 30 minutes of inactivity AND (this is the kicker) delete all files on Desktop, Downloads, and Documents.

I found the Configuration Profile Login Window setting to auto log-off but I’ve seen that if people left unsaved documents over it doesn’t work. It seems to me some scripting is needed here and that’s still a weak spot for me so I’m putting this out to this community in the hopes of some help.

Thanks in advance!

You can force a shutdown, ignoring unsaved files, with the following line: 

 	shutdown -r now

I’d recommend adding some kind of notification, either through a tool like SwiftDialog or with osascript, with an option to cancel the shutdown.


As ​@_Daley said you can use sudo shutdown -r now to force a reboot. MacOS will natively prevent reboots if there is unsaved work. However, also be aware macOS updates dont like to run if a user is not logged in so this could disrupt any overnight OS update workflows you have. As far as deleting the user files a simple script in a policy to loop through /Users and then loop through the contents of ~/Documents, ~/Desktop and ~/Downloads that runs on startup should accomplish what you are needing. Make sure to exempt your local admin account from this workflow as automating file deletion is very risky.


Get the username of the logged in user (say UserNm)

Set an idle timeout

Kill the loginwindow process

Delete /Users/UserNm

This would need to be a script ran as a daemon… I should have some example code, but not got the time to dig it out right now.


Sounds like you want/need authenticated guest mode.  If you’re using Entra MFA and PSSO, then this should be an option for you.


Yeah, look into Guest account. Used this in school labs in the past and it works. 


Yeah, look into Guest account. Used this in school labs in the past and it works. 

There is the baked in Guest account - but you’ll want to test it.  It doesn’t log out inactive users.  We had to create a launchAgent to take care of that.  We were using it in the capacity of “guest mode” for iPads, so naturally we wanted an inactivity log out.