How can I get the position of my application's dock icon using the Accessibility API?
相关问题
- NSOutlineView drag line stuck + blue border
- iphone sdk see size of local file (one created
- How can you detect the connection and disconnectio
- QuickLook Plugin Failing with sandboxing error
- NSTextField font styling resets when selected
相关文章
- Converting (u)int64_t to NSNumbers
- “getter” keyword in @property declaration in Objec
- NSMenuItem KeyEquivalent “ ”(space) bug
- Detect if cursor is hidden on Mac OS X
- NSNumberFormatter doesn't allow typing decimal
- Is subclassing NSNotification the right route if I
- Creating an NSMutableArray with a literal via muta
- adding click action to NSTextField
Found it! Using this forum post as reference, I was able to shape the given sample code to what I needed:
As for Mac OS El Capitan, looks like you aren't supposed to get the position of the icon using Accessibility API. The matter is that the icon isn't located in accessibility objects hierarchy of the app—it can be found in the hierarchy of the system Dock application. A sandboxed app isn't supposed to access the accessibility objects of other apps.
The code in approved answer doesn't yield any warnings of the
sandboxd
daemon in the console, looks like it doesn't violate any rules. It creates the top-level accessibility object with the functionAXUIElementCreateApplication
. The documentation states, that it:Unfortunately, this top-level object is not the ancestor of the Dock icon. I've tried to run the code, and it calculates the position of the first app's main menu item (which has the same title as the app itself). The comparison takes place in this line:
So the output was always the same for my app:
An attempt to access the other app's accessibility object yielded a warning in console. I guess another way to calculate the position of the icon has to be found.