Swift 是否可以确定显示器上基座中图标的x、y位置?

Swift 是否可以确定显示器上基座中图标的x、y位置?,swift,macos,Swift,Macos,我想确定屏幕上MacOS dock中图标的x,y位置。这可能吗?我已经使用过XCode,但还没有找到任何API来实现这一点,在线搜索并没有产生任何有用的结果。这可能是因为我不确定要搜索什么,因为我不是一个经验丰富的MacOS开发人员。我想我应该详尽无遗,只需打印出可用于dock项的所有属性和属性: use application "System Events" tell process "Dock" to tell list 1 to set dockItems to a re

我想确定屏幕上MacOS dock中图标的x,y位置。这可能吗?我已经使用过XCode,但还没有找到任何API来实现这一点,在线搜索并没有产生任何有用的结果。这可能是因为我不确定要搜索什么,因为我不是一个经验丰富的MacOS开发人员。

我想我应该详尽无遗,只需打印出可用于dock项的所有属性和属性:

    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"}

如果位置坐标有点偏离,我应该说我的船坞在屏幕的右侧,并且自动隐藏(屏幕宽度为1440)。

我对Swift没有太多经验,因此如果这完全没有帮助,我道歉。但我知道,使用AppleScript可以获得停靠图标的
{x,y}
位置。@CJK我认为它们可以相互通信,因此如果它与AppleScript一起工作,我应该能够将其合并到我的应用程序中。我会很高兴在斯威夫特只做它,但我会给这个尝试!非常感谢!我的dock在左边,所以应该有点类似:-)我将在本周运行一些实验。我从Applescript获得了这个功能,但从应用程序运行它将不起作用。看起来“系统事件”没有运行,这很奇怪。试图通过将我的应用添加到安全和隐私/可访问性来修复它,但这并没有改变任何事情。