1

我修改了我不久前找到的一些 AppleScript,以某种方式定位最前面的窗口,以便屏幕/停靠/菜单边缘的每一侧都有大约 10px 的边距:

set front_app to (path to frontmost application as Unicode text)

tell application "Finder"
    set _b to bounds of window of desktop
    set scrn_width to item 3 of _b
    set scrn_height to item 4 of _b
end tell

tell application front_app
    activate
    set bounds of window 1 to {10, 35, (scrnWidth - 10), (scrnHeight - 80)}
end tell

问题是我必须为每个窗口单独做。我想只运行一次并让它在每个应用程序的所有窗口上运行。

我尝试修改了大约 5 个不同的脚本,但只是得到了错误。这是我所拥有的:

tell application "System Events"
    tell application "Finder"
        set _b to bounds of window of desktop
        set scrn_width to item 3 of _b
        set scrn_height to item 4 of _b
    end tell
    set _windows to get windows of (application processes whose visible is true)
    repeat with this_window in (items of _windows)
        set bounds of this_window to {10, 35, (scrn_width - 10), (scrn_height - 80)}
    end repeat
end tell

任何帮助,将不胜感激!

4

1 回答 1

3

经过一些工作,这就是我想出的。

tell application "System Events"
    set frontmostApps to every process whose frontmost is true
    if ((count of frontmostApps) = 0) then return
    set frontmostAppAlias to application file of (item 1 of frontmostApps)
end tell

tell application "Finder" to set desktopBounds to bounds of window of desktop

set screenWidth to item 3 of desktopBounds
set screenHeight to item 4 of desktopBounds

tell application (frontmostAppAlias as string)
    set resizableAppWindows to every window whose resizable is true
    repeat with i from 1 to (count of resizableAppWindows)
        set appWindow to item i of resizableAppWindows
        set bounds of appWindow to {10, 35, (screenWidth - 10), (screenHeight - 80)}
    end repeat
end tell

我最初开始尝试在一个tell app "System Events"块内做所有事情,但发现 es 的windowsapplication process似乎不允许与普通windows 相同的调用,即使从脚本定义来看它们应该如此。这导致tell直接阻止应用程序本身。

您可能希望将其包装set bounds在一个try块中,因为可能有一些应用程序的可调整大小的窗口设置了最大大小限制,这可能会导致错误。

于 2013-02-23T10:45:30.913 回答