I was wondering if there was a way to retrieve the URL of the active window, if it has one. The following code should work, but it doesn't, the title variable becomes "", and I don't get any new information.
I'm positive that that's because I'm using kAXURLAttributes of the wrong object, but I have no clue which one should I copy it from... Apple's documentation has very few explanations.
AXUIElementRef appElem = AXUIElementCreateApplication(pid), window = nullptr;
CFStringRef title = nullptr;
if (!appElem) { return; }
if (AXUIElementCopyAttributeValue (appElem, kAXFocusedWindowAttribute,
reinterpret_cast<CFTypeRef*>(&window)) != kAXErrorSuccess && appElem)
CFRelease(appElem);
if(AXUIElementCopyAttributeValue (window, kAXTitleAttribute,
reinterpret_cast<CFTypeRef*>(&title))!=kAXErrorSuccess && window)
CFRelease(window);
focusedAppTitle = QString::fromCFString(title);
if(AXUIElementCopyAttributeValue (window, kAXURLAttribute,
reinterpret_cast<CFTypeRef*>(&title))!=kAXErrorSuccess)
CFRelease(window);
}