r/applescript • u/Mr_Antero • Oct 30 '22
How to setup command to - Autoquit app if opened
Hi. I’m trying to setup a user on my Mac that has only limited access to a handful of specific apps related to workflow.
I would like to setup an apple script (or automation) that automatically closes an app if opened. For example, Apple mail.
And would repeatedly do so for length of user session if repeat access is attempted. For example, Apple Mail would immediately close if I attempted to open it.
Or would it be better to create a script, where app open command isn’t acknowledged?
6
Upvotes
2
u/stephancasas Oct 30 '22
I think parental controls/ScreenTime would work better for your use case, but if you still aren’t getting the flexibility you want out of that, Hanmerspoon has the ability to watch app processes.
Your issue is going to be preventing the user from overriding whatever you create, which is why I’d opt for parental controls. To make a process/script persistent, you’d need to write it into
launchd, but that requires considerably more effort.2
u/estockly Oct 31 '22
You could do a stay-open application that looks for the specific processes in System Events every 2 minutes or so, then quit it if it comes up
2
u/copperdomebodha Oct 31 '22
This came up a week ago and that post has a functional solution. It was based on selecting apps that are NOT permitted to run. It sounds like you are looking to specify the apps that ARE allowed to run. I'll post a variation that behaves in that manner.
2
u/copperdomebodha Nov 02 '22
Save this as a stay-open application. Drop apps on it to allow them to run. The Finder is always allowed to run.