The Accessibility API is almost complete with the basic AXUIElement portal call in article 1 and the AXObserver portal listener in article 2. But if we want to make our code more robust, we have to do more error and exception handling. And just the org.eclipse.swt.accessibility API function, basically will return a AXError, let’s to make judgment calls and exception handling

AXError

First of all, what is an AXError? Again, see axError.h for details

AXError is an enumeration and is Int32. What values does it have?

  1. success: it’sRawValuefor0. It means that the API call was successful, but it does not mean that the value obtained is necessarily valuable, which is important to note. So when you make a judgment, you need to make a double judgment. If AXError succeeds and value has a value:
var value : AnyObject? let axError:AXError = AXUIElementCopyAttributeValue(applicationRef! , kAXWindowsAttribute as CFString, & Value) if axError ==. Success {if let Windows = value as? [AXUIElement]{print("all Windows \(Windows)")}}Copy the code
  1. Failure: itRawValuefor- 25200.. System exception, an error thrown by the system. Failure to allocate memory to an object.
  2. IllegalArgument: itRawValuefor- 25200.. An invalid value was passed to aAccessibility APIThe function.
  3. InvalidUIElement: itRawValuefor- 25202.. The API function does not support thisAXUIElement.
  4. InvalidUIElementObserver: itRawValuefor- 25203.. API functions do not support and accept thisAXObserver.
  5. CannotComplete: itRawValuefor- 25204.. A function cannot complete, usually when the program is unresponsive or busy.
  6. AttributeUnsupported itRawValuefor- 25205.. Is that theAXUIElementDoes not support theattribute.
  7. ActionUnsupported itRawValuefor- 25206.. Is theAXUIElementDoes not support theaction.
  8. NotificationUnsupported itRawValuefor- 25207.. Is theAXUIElementDoes not support thenotification.
  9. NotImplemented itRawValuefor--25208. Indicates that a method or function is not declared or implemented. Generally occurs when the program is not allowed to useAccessibility API
  10. NotificationAlreadyRegistered itRawValuefor- 25209.. Is thenotificationIt already exists. This occurs when the same key is repeatedly added to the notification
  11. NotificationNotRegistered itRawValuefor- 25210.. Used to judge thenotificationWhether it has been registered.
  12. ApiDisabled itRawValuefor- 25211.It is not allowed to be usedAccessibility API. Need to be inSystem Preference -> Security & Privacy -> AccseeibilityInside add.
  13. NoValue: itRawValuefor- 25212.. Indicates that the requested Value does not exist.
  14. ParameterizedAttributeUnsupported: itRawValuefor- 25213.. Is theAXUIElementNot allowed to useparameterizedAPI functions
  15. NotEnoughPrecision: itRawValuefor- 25214..Not accurate. I haven’t met this author yet
Copy the code