fix: AXManualAccessibility showing failure (#38102)

fix: AXManualAccessibility showing failure
This commit is contained in:
Shelley Vohr 2023-04-26 19:41:56 +02:00 committed by GitHub
parent a0a44f07dd
commit f35b9b3f06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View file

@ -28,6 +28,8 @@ On macOS, third-party assistive technology can toggle accessibility features ins
Electron applications by setting the `AXManualAccessibility` attribute
programmatically:
Using Objective-C:
```objc
CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");
@ -43,5 +45,16 @@ CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");
}
```
Using Swift:
```swift
import Cocoa
let name = CommandLine.arguments.count >= 2 ? CommandLine.arguments[1] : "Electron"
let pid = NSWorkspace.shared.runningApplications.first(where: {$0.localizedName == name})!.processIdentifier
let axApp = AXUIElementCreateApplication(pid)
let result = AXUIElementSetAttributeValue(axApp, "AXManualAccessibility" as CFString, true as CFTypeRef)
print("Setting 'AXManualAccessibility' \(error.rawValue == 0 ? "succeeded" : "failed")")
```
[a11y-docs]: https://www.chromium.org/developers/design-documents/accessibility#TOC-How-Chrome-detects-the-presence-of-Assistive-Technology
[setAccessibilitySupportEnabled]: ../api/app.md#appsetaccessibilitysupportenabledenabled-macos-windows