Post not yet marked as solved
I'm wondering if it is possible to get system wide NSEvent.cursorUpdate (or cursor events in any other form?)
NSEvent.addGlobalMonitorForEvents(matching: .cursorUpdate, handler: cursorEventReceived(_:))
That isn't working and all I documentation and examples I can find are local and involving a the apps view but my app does not have any views and still need to get them if possible.
Post not yet marked as solved
I have a prelogin agent that works as expected but now I'm unsure of how do I go about saving/removing its plist as needed? I tried using FIleManager but for obvious reasons I get "You don’t have permission to save the file" and I'm not able to find a way to prompt for user permission from within my swift app.
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.
Post not yet marked as solved
I have swift dylib that I call from a simple cSharp program through mono. I need the dylib to stay alive and listen to keyboard, mouse, application events as well as receiving commands to move mouse, etc. Looking online I found some suggestion to keep the process running and while they do keep the process alive I'm unable to receive the events I add monitors for.
NSEvent.addGlobalMonitorForEvents(matching: mEvent.eventMask, handler: globalEventCallBack"
I have tried Runloop.main.run DispatchGroup, Semaphore and while I understand why some don't work (they block the main thread and that's where the events are delivered) I don't understand others.
So here I'm in search of suggestions of how to keep my process alive and still get the events.