开发者

rb-appscript: Accessing parent reference?

Is there an easy way to find the parent element reference of a reference?

For example, suppose I have the following reference:

ref = app("System Events").processes["Safari"].windows[1].buttons[1]

I would like to do something similar to the following:

ref.parent  # => app("System Events").processes["Safari"].windows[1].buttons

Or even:

ref.parent  # => app("System Events").processes["Safari"].windows[1]

I've looked over the documentation and guides and haven't been successful. I also tried a big no-no by monkey-patching th开发者_开发问答e Appscript::Reference class and adding my own methods but it starts to break my specs in ways that are difficult to troubleshoot. I also thought about using eval but that seemed like a worse idea. Any thoughts?


After a bit of chin scratching, I think I might have a solution:

ref = app("System Events").processes["Safari"].windows[1].buttons[1]
ref.attributes[its.name.eq("AXParent")].value.get

Returns

[app("/System/Library/CoreServices/System Events.app").application_processes["Safari"].windows["rb-appscript: Accessing parent reference? - Stack Overflow"]]

Is that the kind of thing?

Ian

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜