2013-02-23 36 views
1

我修改了一些前面找到的AppleScript,以某種方式放置最前面的窗口,因此屏幕/停靠欄/菜單欄的邊緣每邊都有大約10px的邊距:Applescript設置所有窗口的窗口範圍

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 

任何幫助,將不勝感激!

回答

2

經過了一些工作,這就是我想出的。

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"塊內的所有內容,卻發現window S的application process ES似乎並沒有讓相同的呼叫正常window S,即使從腳本定義,它們應該。這導致了tell塊直接對應用程序本身。

您可能想將set bounds包裝在try區塊中,因爲可能會有一些應用程序的可調整大小的窗口具有設置的最大大小限制,這可能會導致錯誤。

+0

謝謝!我稍微修改了一下,以便它可以遍歷所有打開的應用程序(需要一段時間,哈哈 - 我在AppleScript上不是很棒)。 https://gist.github.com/anonymous/5020503 – 2013-02-23 17:14:26