So I have a bit of complicated setup, but let me see if I can simplify
I am running a mono application on a remote OSX machine. This application can occasionally hard-crash the mono runtime.
There is a recovery shell script running every 2 minutes via launchctl. This script detects mono death by ps ax | grep mono
If the process is dead, it runs the following applescripts to spawn a new Terminal window
osascript -e 'tell app "Terminal" to close every window'
osascript -e 'tell app "Terminal" to do script "mono --server myapp.exe'
the reason I am running the mono app in a terminal window in 'user space' is because the app interacts with other windowed applications and cannot be spawned directly from the appchecking.sh file
However sometimes the above process fails with the following error
$ osascript -e 'tell application "Terminal" to open'
31:35: execution error: An error of type -10810 has occurred. (-10810)
What's weird is during this state, if I SSH into the affected machine, it appears Terminal is not running. A ps ax | grep Terminal
yields nothing. However, if I VNC into the affected workstation, the Terminal process suddenly becomes visible, and my script no longer returns that error
The OSX machine is set up to auto log in as a default user. And if I reboot a machine in this state it comes back just fine. I guess what is the source of my -10810 error (guessing somehow I am being logged out and my appcheck.sh is not running as my user anymore?)