I'm writing a Agent Application that records the Screen and I'm trying to keep the recording going even when the user logs out. I've been reading about LaunchAgents and LaunchDaemons. From what I understand a Prelogin LaunchAgent is my best bet since I need NSApplication to keep my process going and to access the screens. I'm only able to relaunch the app after login or to reopen the app when the os closes it. But the recording process is interrupted. Here is what I have as far as my LaunchAgent.
My prelogin LaunchAgent (to open the app during the LoginWindow context)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.myApp.prelogin</string>
<key>LimitLoadToSessionType</key>
<string>LoginWindow</string>
<key>RunAtLoad</key>
</true>
<key>ProgramArguments</key>
<array>
<string>/Library/myApp/myAgent0</string>
<string>service</key>
<array>
<key>QueueDirectories</key>
<array>
<string>/etc/myApp/service</string>
</array>
</dict>
</plist>
Per user launch agent (to keep the application open while a file exists in the path of QueDirectories)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.myApp.peruser</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Library/myApp/vmyAgent0</string>
<string>service</string>
</array>
<key>QueueDirectories</key>
<array>
<string>/etc/myApp/service</string>
</array>
</dict>
</plist>
And then a daemon that I was suggested to add.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.myApp.server</string>
<key>ProgramArguments</key>
<array>
<string>/Library/myApp/myAgent0</string>
<string>-service</string>
</array>
<key>QueueDirectories</key>
<array>
<string>/etc/myApp/service</string>
</array>
</dict>
</plist>
Currently the application get closed down when the user logs out and gets reopened when the user logs back in or every time I close it (until I remove the file from QueueDirectories). I'm not sure if it gets open during LoginWindow but I don't see any recordings of that so I don't think it does. I know it is possible since VNC viewer does it (you can remotely log into your Mac). I'm not even sure I'm on the right track and I found this other question which tells me I'm on the wrong side using NSApplication for something like this? I'm in need of confirmations lol.
Thank you in advance.