Instance Property
menuBarOwningApplication
Returns the app that owns the currently displayed menu bar.
Declaration
@property(readonly, strong) NSRunningApplication *menuBarOwningApplication;
Return Value
The running app instance for the app that owns the displayed menu bar.
Source from: https://developer.apple.com/documentation/appkit/nsworkspace/1525848-menubarowningapplication?language=objc
int GetActivePid(){
@autoreleasepool {
NSRunningApplication*r = [[NSWorkspace sharedWorkspace] menuBarOwningApplication];
if(r)
return [r processIdentifier];
}
return 0;
}
Project compiled as dinamic library and used in c++ program where c++ program do simple work.
#include <iostream>
#include "MyObject-C-Interface.h"
#include <unistd.h>
int main()
{
while(1){
pid_t pid = GetActivePid();
std::cout << "active pid: " << pid << " mine: " << getpid() << std::endl;
sleep(2);
}
return 0;
}
Output I, get no matter what app I set to be "active" or what ever I should use as expression(frontmost, active, owning the current displayed bar... etc.)
active pid: 9731 mine: 10457
active pid: 9731 mine: 10457
active pid: 9731 mine: 10457
active pid: 9731 mine: 10457
active pid: 9731 mine: 10457
active pid: 9731 mine: 10457
....
.. etc... never change nothing.
Im I expecting the wrong output or documentation is not right ?