我正在尝试编写一个 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
所以我很困惑。
我究竟做错了什么?我怎样才能解决这个问题?