Skip to content

Parameterized attributes do not work! #44

@AlbatorLaho

Description

@AlbatorLaho

I've encountered some problems with parameterized attributes. (running MacOS 12, Monterey)

The Attribute enum for parameterized values are incorrect... they shouldn't end with Parameterized.

enum Attribute {
    case boundsForRangeParameterized = "AXBoundsForRangeParameterized"
    // should be:
    case boundsForRangeParameterized = "AXBoundsForRange"
}

Personally, I would also like the parameterized attributes to be separated into another enum.
I'm not sure why they're in the same enum in the first place... they're never interchangeable are they?
I realize it's probably for simplicity of functions like attributeIsSupported... but I'd still think it makes sense for them to be separated.

The other thing I found is that the parameterizedAttribute in UIElement doesn't work correctly.
I was trying to set AXBoundsForRange and passing in a CFRange, but it would throw an AXError.IllegalArgument error.
I figured out that it's because the param value does not use packAXValue, unlike setAttribute.

open func parameterizedAttribute<T, U>(_ attribute: String, param: U) throws -> T? {
    ...
    let error = AXUIElementCopyParameterizedAttributeValue(
        element, attribute as CFString, param as AnyObject, &value
    )
    // should be something like this:
    let error = AXUIElementCopyParameterizedAttributeValue(
        element, attribute as CFString, packAXValue(param), &value
    )
    ...
}

I can't easily test this fully, since I can't access packAXValue in an extension (because it's fileprivate), but doing manual conversion to an AXValue seems to fix it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions