I will answer my own question:
It possible with accessibility api & carbon
a) register a wide event:
AXUIElementRef _systemWideElement = AXUIElementCreateSystemWide();
b)convert carbon to screen point
- (CGPoint)carbonScreenPointFromCocoaScreenPoint:(NSPoint)cocoaPoint {
NSScreen *foundScreen = nil;
CGPoint thePoint;
for (NSScreen *screen in [NSScreen screens]) {
if (NSPointInRect(cocoaPoint, [screen frame])) {
foundScreen = screen;
}
}
if (foundScreen) {
CGFloat screenMaxY = NSMaxY([foundScreen frame]);
thePoint = CGPointMake(cocoaPoint.x, screenMaxY - cocoaPoint.y - 1);
} else {
thePoint = CGPointMake(0.0, 0.0);
}
return thePoint;
}
c) get process under mouse
NSPoint cocoaPoint = [NSEvent mouseLocation];
if (!NSEqualPoints(cocoaPoint, _lastMousePoint)) {
CGPoint pointAsCGPoint = [self carbonScreenPointFromCocoaScreenPoint:cocoaPoint];
AXUIElementRef newElement = NULL;
if (AXUIElementCopyElementAtPosition( _systemWideElement, pointAsCGPoint.x, pointAsCGPoint.y, &newElement ) == kAXErrorSuccess) {
NSLog(@"%@",newElement);
}
_lastMousePoint = cocoaPoint;
}
Credits to https://developer.apple.com/library/mac/samplecode/UIElementInspector/Introduction/Intro.html
nslog gives something like <AXUIElement 0x6000000583c0> {pid=39429}
ps aux | grep 39429
:39429 0.2 5.5 5109480 916500 ?? U 1:57PM 3:34.67 /Applications/Xcode.app/Contents/MacOS/Xcode