atomacos icon indicating copy to clipboard operation
atomacos copied to clipboard

looking to set selectedchildren attribute

Open jbflow opened this issue 5 years ago • 6 comments

Trying to figure out how to set the selectedchildren attribute of an object.

I know in Obj-C it's AXUIElementSetAttributeValue, but can't figure out how to do it with this.

jbflow avatar May 29 '20 00:05 jbflow

OK I figured it out - using __ setattr __('AXSelectedChildren', AXUIElement.ref)

Don't know if that's the best way but it works.

jbflow avatar May 29 '20 23:05 jbflow

Try using x.AXSelectedChildren = AXUIElement.ref

__setattr__ is supposed to be called when you try do to that. python docs

__setattr__ definition checks if it's an AX attribute https://github.com/daveenguyen/atomacos/blob/master/atomacos/_a11y.py#L82

daveenguyen avatar May 30 '20 01:05 daveenguyen

Yeah that was the first thing I tried, I thought that was the case but for some reason it doesn't work. No error or anything, it appears to work, but doesn't do what is expected in the GUI. I was really trying to understand the functioning by looking at ApplicationServices and seeing what I needed to pass to AXUIElementSetAttributeValue when I came across this and thought I'd try it. I wasn't really expecting it to work tbh.

jbflow avatar May 30 '20 09:05 jbflow

OK it was my mistake, I needed to do it like this x.AXSelectedChildren = [AXUIElement.ref]

and also I have to use a direct reference to the AXUIElement, when it's stored in a variable it doesn't work.

jbflow avatar May 30 '20 09:05 jbflow

So if I store the list of AXChildren as a variable and then try to set AXSelectedChildren from that list using the index it just doesn't do anything, it has to be set from the original element and AXChildren[x].ref. I guess that's something to do with how the Accessibility stuff works?

jbflow avatar May 30 '20 09:05 jbflow

I think as long as value you give is a CFTypeRef based on the apple docs. Not sure what makes something CFTypeRef. Probably something that comes from objc library calls. .ref are original reference to objects from objc, I believe.

https://github.com/daveenguyen/atomacos/blob/master/atomacos/_a11y.py#L259 https://github.com/daveenguyen/atomacos/blob/d520135ff03ba548140dec07bd1b4ef2a2ae0e5c/atomacos/_macos.py#L142

https://developer.apple.com/documentation/applicationservices/1460434-axuielementsetattributevalue?language=objc

daveenguyen avatar May 30 '20 09:05 daveenguyen