r/applescript • u/dpwell • Sep 26 '23
Program to log a user out at a certain time
Hi, I'd like to write a program that either logs a user out of their Apple laptop at a certain time, or closes all apps. If the user tries to overide the program by reopening an app, the program would close it again. In order to overide the program itself by closing it, the user would need a password.
Before I take the time to start learning it, is this something I could write with Applescript?
Thanks.
2
Upvotes
1
u/Perfect-Extent9215 Sep 26 '23
I’m not sure with a script, but I basically achieve the same things you’re asking for with my kids using apple’s screen time feature.
1
u/copperdomebodha Sep 26 '23
All your goals are achievable except that there is no code that will prevent a user from quiting an AppleScript app. Applescript's can include a quit handler and the Quit handler must include a continue quit statement for the app to quit. You can choose not to include that function call, but anyone can force quit any app.
Twin applications that check that each other are running could prevent a user from quitting them both. But you can force quit multiple apps simultaneously. delay / check running apps loops in the quit handler could provide enough overlap of the quit times that the partner app could relaunch the recently quit app. Ugly and complicated.
Creating your app as an Agent application may work.