OK this question is 6 months old, so you probably solved your problem by now, but in case it is useful ...
I solved a similar problem with the application I'm working on, watching for application deactivation through NSWorkspace.
You may have a property:
NSRunningApplication* _previousRunningApplication;
And update this property by watching NSWorkspaceDidDeactivateApplicationNotification
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(anyApplicationDeactivated:) name:NSWorkspaceDidDeactivateApplicationNotification object:nil];
Then, when your application completes execution, simply activate the active application using:
If there is a possibility that the last line may be called while your application is inactive, then first you need to check if it uses [NSApp isActive]
(or you can cause some amazing and annoying behavior for users ...)
If you find a simpler solution, I would be interested to know about it.
In case this code is useful to everyone, I created a separate class to handle all this and checked it on Github:
http://github.com/mjrit/MJRAppReactivation
source share