macOS Accessibility Inspector does not work with Slack

214 Views Asked by At

When I'm using macOS's Accessibility Inspector on apps like notes and Apple mail, I get all the window's children elements. If I use the Inspector on Slack, though, I only get the window and nothing of the content.

Is there a way to force slack to expose its children to the inspector somehow? Same goes for WhatsApp Web and the Apple Pages Canvas.

1

There are 1 best solutions below

0
On BEST ANSWER

Found the answer here https://www.electronjs.org/docs/latest/tutorial/accessibility#macos

The AXManualAccessibility Attribute of the App must be set to kCFBooleanTrue.

This is how it's done:

  1. Get the process ID of the current app
  2. Create an AXUIElement from the app using the process ID
  3. Set the AXManualAccessibility of the newly created AXUIElement to kCFBooleanTrue

Now all elements of the App are inspectable using the Accessibility manager. This not only works for all electron apps, but also apps like Pages or MS Word.

Swift

let kAXManualAccessibility: CFString = "AXManualAccessibility" as CFString;

private func enableAccessibility() {
    guard let processIdentifier = NSWorkspace.shared.frontmostApplication?.processIdentifier else { return }
    let appRef = AXUIElementCreateApplication(processIdentifier)

    AXUIElementSetAttributeValue(appRef, kAXManualAccessibility, kCFBooleanTrue)
}

Objective C

CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");

+ (void)enableAccessibility:(BOOL)enable inElectronApplication:(NSRunningApplication *)app
{
    AXUIElementRef appRef = AXUIElementCreateApplication(app.processIdentifier);
    if (appRef == nil) return;

    CFBooleanRef value = enable ? kCFBooleanTrue : kCFBooleanFalse;
    AXUIElementSetAttributeValue(appRef, kAXManualAccessibility, value);
    CFRelease(appRef);
}