AppleScript - 根据 processName 和 windowTitle 最小化所有 windows
AppleScript - Minimize all windows based on processName and windowTitle
我正在尝试遍历所有进程并获取每个进程的 Main window 的 window 标题。基于window标题,我想使过程隐藏()。
tell application "System Events"
repeat with aProcess in processes
tell aProcess
tell (1st window whose value of attribute "AXMain" is true)
set windowTitle to value of attribute "AXTitle"
if windowTitle is not "Whosebug" then
set visible of aProcess to false
end if
end tell
end tell
end repeat
end tell
我收到了
execution error: System Events got an error: Can’t get window 1 of item 1 of every process whose value of attribute "AXMain" = true. Invalid index. (-1719)
是不是所有进程都没有Main Window?
Is it because of all the processes not having a Main Window?
更多的是并非所有进程都具有 windows(任何类型)。
tell application id "com.apple.systemevents" to tell (every process ¬
whose front window's class = window and the front window's ¬
title does not contain "foobar") to set visible to true
细分:
tell application id "com.apple.systemevents" to
: 将命令定向到 系统事件。唯一的区别是我用它的包标识符而不是它的名字来引用应用程序。这不是很重要,但应用程序的包标识符比它的文件名更不可能改变。
tell (every process whose front window's class = window
: 这是检索至少有一个 window 的进程列表的有效方法,因为它过滤掉没有 windows 的进程,class of its front window
将成为 missing value
.
and the front window's title does not contain "foobar"
: 将进程过滤到仅 windowed 应用程序后,这将通过 name/title 的 window。 title
属性 从 attribute "AXTitle"
获取其值,但访问 属性 和 attribute
object。在这里,我选择放宽对匹配 window 的标题施加的相等性,这样您就不需要使用 window 的完整标题,而是您选择的明智选择的词.
to set visible to true
: 隐藏之前返回的进程
我正在尝试遍历所有进程并获取每个进程的 Main window 的 window 标题。基于window标题,我想使过程隐藏()。
tell application "System Events"
repeat with aProcess in processes
tell aProcess
tell (1st window whose value of attribute "AXMain" is true)
set windowTitle to value of attribute "AXTitle"
if windowTitle is not "Whosebug" then
set visible of aProcess to false
end if
end tell
end tell
end repeat
end tell
我收到了
execution error: System Events got an error: Can’t get window 1 of item 1 of every process whose value of attribute "AXMain" = true. Invalid index. (-1719)
是不是所有进程都没有Main Window?
Is it because of all the processes not having a Main Window?
更多的是并非所有进程都具有 windows(任何类型)。
tell application id "com.apple.systemevents" to tell (every process ¬
whose front window's class = window and the front window's ¬
title does not contain "foobar") to set visible to true
细分:
tell application id "com.apple.systemevents" to
: 将命令定向到 系统事件。唯一的区别是我用它的包标识符而不是它的名字来引用应用程序。这不是很重要,但应用程序的包标识符比它的文件名更不可能改变。tell (every process whose front window's class = window
: 这是检索至少有一个 window 的进程列表的有效方法,因为它过滤掉没有 windows 的进程,class of its front window
将成为missing value
.and the front window's title does not contain "foobar"
: 将进程过滤到仅 windowed 应用程序后,这将通过 name/title 的 window。title
属性 从attribute "AXTitle"
获取其值,但访问 属性 和attribute
object。在这里,我选择放宽对匹配 window 的标题施加的相等性,这样您就不需要使用 window 的完整标题,而是您选择的明智选择的词.to set visible to true
: 隐藏之前返回的进程