This cannot be done. Apple is very restrictive when it comes to things like this.
The way I understand it is this:
Apple limits the API to your app (you can’t affect other apps or the OS in any major way-this stop malicious behaviour)
Your app is ‘sandboxed’ meaning it’s on it’s own, it can’t see if Safari has any pages open, or monitor what game you just exited out of or anything like that. Your app is in effect, isolated.
You can write anything to a file, just getting what you want to write (in this case) is not possible
tl;dr. No, your app is in it’s own little ‘sandbox’ it can’t monitor anything but itself, Apple doesn’t allow it nor do they provide any programming library to do so.
solved Track Running Apps [closed]