如何设置系统偏好设置的 X 和 Y window?

How do I set the X and Y of the System Preferences window?

我正在尝试打开“系统偏好设置”,然后将其定位到右边缘或左边缘(不更改其大小)。我不断收到错误消息:

tell application "System Preferences" to set x and y to 20

错误:

Can’t set x and y to 20. Access not allowed.

我喜欢使用应用程序 "System Events" 访问 运行 进程和 UI 元素。我最终得到了这样的解决方案:

tell application "System Preferences" to activate

tell application "System Events"
    tell process "System Preferences"
        tell first window
            set position to {100, 100}
        end tell
    end tell
end tell

玩得开心!迈克尔/汉堡

您可以使用 bounds 属性 更改 window 的位置。

set {x, y} to {0, 22} -- position
tell application "System Preferences"
    tell (get bounds of window 1) to set {tRig, tBot} to {(item 3) - ((item 1) - x), (item 4) - ((item 2) - y)}
    set bounds of window 1 to {x, y, tRig, tBot} -- change position of the window without changing it's size
end tell