是否可以在后台移动窗口(无需窃取焦点)

时间:2012-11-01 08:40:57

标签: macos window applescript move foreground

我想为一个同时打开多个窗口的应用程序编写脚本。 当他们需要用户对他们执行操作时,他们中的一些人会弹出到前台。

但是,对于前景中的每个窗口,其背后都有许多其他窗口(在后台)。 我想将特定的背景窗口移动到屏幕的不同位置。

我想知道这是否可以与AppleScript一起使用但没有匆匆忙忙的焦点;移动时,它们不应该出现在前景中。

1 个答案:

答案 0 :(得分:1)

在Safari中打开2个窗口(或更多)并尝试此操作。它将第二个窗口向右移动5个像素。此代码应该适用于您的应用程序以及系统事件了解窗口并可以重新定位其他应用程序。请注意,窗口也具有您可能想要使用的大小属性。

tell application "System Events"
    tell process "Safari"
        set theWindows to windows
        if (count of theWindows) is greater than or equal to 2 then
            set p to position of (item 2 of theWindows)
            set position of window 2 to {(item 1 of p) + 5, item 2 of p}
        end if
    end tell
end tell