如何设置“系统偏好设置”窗口的X和Y?

时间:2015-01-13 05:59:30

标签: applescript

我正在尝试打开系统偏好设置,然后将其放置在右边缘或左边缘(不改变它的大小)。我一直在收到错误:

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

错误:

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

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

我喜欢使用应用程序“系统事件”来访问正在运行的进程和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

玩得开心!迈克尔/汉堡