Reputation: 3596
I want to determine the x,y position of an icon in the MacOS dock on the screen. Is this possible? I've played around a bit with XCode but haven't really found any API's to do this, searching online didn't yield anything useful. Maybe that's because I'm not sure what to search for as I'm not a very experienced MacOS developer.
Upvotes: 4
Views: 578
Reputation: 6092
I thought I would be exhaustive and just print out all the properties and attributes that are available for the dock items:
use application "System Events"
tell process "Dock" to tell list 1 to set dockItems to a reference to ¬
(every UI element whose role is "AXDockItem")
get the name of the dockItems
--> {"Safari", missing value, "Finder", "App Store", "Launchpad", "Safari", "Google",
--> "Spark", "Calendar", "Notes", "Photo Booth", "Photos", "Messages", "Telegram Desktop",
--> "WhatsApp", "iTunes", "Accessibility Inspector", "Script Editor", "System Preferences",
--> "Google Chrome", "Atom", "Automator", missing value, "CK", "WebCatalog Apps",
--> "Applications", "Trash"}
get the position of the dockItems
--> {{1435, 47}, {1435, 78}, {1435, 81}, {1435, 112}, {1435, 143}, {1435, 174},
--> {1435, 206}, {1435, 237}, {1435, 268}, {1435, 299}, {1435, 330}, {1435, 362},
--> {1435, 393}, {1435, 424}, {1435, 455}, {1435, 486}, {1435, 517}, {1435, 549},
--> {1435, 580}, {1435, 611}, {1435, 642}, {1435, 673}, {1435, 704}, {1435, 736},
--> {1435, 750}, {1435, 781}, {1435, 812}, {1435, 843}}
get the name of the attributes of ¬
some UI element in the dockItems
--> {"AXRole", "AXRoleDescription", "AXSubrole", "AXTitle", "AXParent", "AXChildren",
--> "AXPosition", "AXSize", "AXFrame", "AXTopLevelUIElement", "AXSelected",
--> "AXShownMenuUIElement", "AXStatusLabel", "AXProgressValue"}
get the properties of ¬
some UI element in the dockItems
--> {minimum value:missing value, orientation:missing value, position:{1435, 785}, class:UI element,
--> accessibility description:missing value, role description:"folder dock item",
--> focused:missing value, title:"WebCatalog Apps", size:{39, 30}, help:missing value,
--> entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXDockItem",
--> value:missing value, subrole:"AXFolderDockItem", selected:false, name:"WebCatalog Apps",
--> description:"folder dock item"}
In case the position coordinates throw you off a little, I should say that my dock is on the right-hand-side of my screen, and auto-hides (my screen width is 1440).
Upvotes: 5