ins*_*get 3 macos applescript resize window
我正在尝试编写一个applescript脚本,允许我随时调整所有正在运行的应用程序的窗口大小(我目前使用Stay,但发现它有时很麻烦,所以我想"重新发明"它)
我一直在关注一些applecripting教程并提出以下代码来做到这一点,但它是错误的:
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"
Run Code Online (Sandbox Code Playgroud)
问题是,当此代码遇到我唯一的终端窗口(有几个打开的选项卡)时,它会出错: 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
Run Code Online (Sandbox Code Playgroud)
所以我很困惑.
我究竟做错了什么?我怎样才能解决这个问题?
tell application "Finder"
set {0, 0, dtw, dth} to bounds of window of desktop
end tell
tell application "System Events"
repeat with p in (processes where background only is false)
tell p
if name is not in {"Finder"} then
set position of windows to {0, 0}
set size of windows to {dtw, dth}
end if
end tell
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
tell application "Finder"
set dtb to bounds of window of desktop
end tell
tell application "System Events"
bundle identifier of processes where background only is false
end tell
repeat with bid in result
tell application id bid
try
if name is not in {"Finder"} then
set (bounds of windows where visible is true) to dtb
end if
end try
end tell
end repeat
Run Code Online (Sandbox Code Playgroud)
我用这个脚本来最大化窗口:
try
tell application "Finder" to set dtb to bounds of window of desktop
tell application (path to frontmost application as text)
if name is in {"Terminal"} then
error
else
set bounds of window 1 to dtb
end if
end tell
on error
tell application "System Events" to tell (process 1 where it is frontmost)
try
click (button 1 of window 1 where subrole is "AXZoomButton")
end try
end tell
end try
Run Code Online (Sandbox Code Playgroud)
在许多没有基本AppleScript支持的应用程序中,缩放按钮也可以最大化窗口以填充屏幕.