【发布时间】:2013-01-13 17:47:24
【问题描述】:
我正在尝试编写一个 applescript 脚本,它允许我在选择时调整所有正在运行的应用程序的所有窗口的大小(我目前使用Stay,但发现它有时会出现故障,所以我想“重新-发明”)
我一直在关注一些applescripting教程,并提出了以下代码,但它有问题:
tell application "Finder"
set rect to bounds of window of desktop
end tell
property excludedApplicationNames : {"Finder"}
tell application "System Events"
say "a"
repeat with theProcess in processes
say "b"
if background only of theProcess is false then
say "c"
set theProcessName to name of theProcess as string
if theProcessName is not in excludedApplicationNames then
say theProcessName
tell application theProcess
set bounds of windows of process theProcess to rect
end tell
end if
end if
end repeat
end tell
say "done"
问题是当这段代码遇到我唯一的终端窗口(有几个打开的标签)时,它报错:System Events got an error: Can’t set application (item 2 of every process) to {0, 0, 1280, 900}.System Events got an error: Can’t set application (item 2 of every process) to {0, 0, 1280, 900}.
将tell application theProcess 更改为tell application theProcessName 没有帮助(同样的错误),将其更改为tell application "System Events" 也没有帮助(错误:System Events got an error: Can’t make item 2 of every process into type integer.)
有趣的是,这按预期工作:
tell application "Finder"
set rect to bounds of window of desktop
end tell
tell application "Terminal"
repeat with theWindow in windows
set bounds of theWindow to rect
end repeat
end tell
所以我很困惑。
我究竟做错了什么?我该如何解决这个问题?
【问题讨论】:
-
我发现
tell application "Finder" to set window 1's bounds to {0, 0, 600, 600}也有问题。它适用于某些应用程序,例如 Finder 和 iTunes,但 it doesn't redraw shadows for Safari。而且 Preview 根本不支持 AppleScript,所以它的窗口不能被 AppleScript 调整大小。
标签: macos resize window applescript