Macos Applescript为所有窗口设置窗口边界
我修改了前一段时间找到的一些AppleScript,将最前面的窗口放置在屏幕/驳接/菜单栏边缘的每一侧大约有10px的边距:Macos Applescript为所有窗口设置窗口边界,macos,applescript,Macos,Applescript,我修改了前一段时间找到的一些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_heigh
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
任何帮助都将不胜感激 经过一番努力,我想到了以下几点
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
我最初尝试在告诉应用程序“系统事件”
块中执行所有操作,但发现应用程序进程的窗口
es似乎不允许与正常窗口
s相同的调用,尽管从脚本定义来看,它们应该允许。这导致了直接向应用程序本身发送tell
块
您可能希望将设置边界
包装在try
块中,因为可能会有一些应用程序的可调整窗口设置了最大大小限制,这可能会导致错误。谢谢!我稍微修改了一下,这样它就可以在所有打开的应用程序中循环(这需要一段时间,哈哈——我不太擅长AppleScript)。