我的AppleScript程序需要一些帮助。
我想列出所有打开并在底座上的窗口,所以我尝试了这个:
tell application "System Events"
set procs to processes
set windowInDock to {}
repeat with proc in procs
try
if exists (window 1 of proc) then
repeat with w in (every window of proc whose miniaturized is true)
copy a & w's miniaturized to the end of windowInDock
end repeat
end if
end try -- ignore errors
end repeat
end tell
return windowInDock
但它返回空数组。
我尝试列出所有窗口并获得小型参数(w小型化),但它不起作用。
你有什么想法吗?
谢谢!
答案 0 :(得分:3)
存在命令适用于任何对象,但系统事件的窗口属性与应用程序的窗口属性不同(例如,没有小型化)属性)。如果你没有忽略所有这些错误,你会看到错误 - 在try语句中包装一堆代码而不至少记录错误只是要求它。
您可以做的是获取应用程序列表,然后询问他们以获取有关其窗口的信息。不知道你要用一个真值列表做什么,所以在我的例子中我只使用了窗口索引:
tell application "System Events" to set theNames to name of processes whose background only is false
set windowsInDock to {}
repeat with appName in theNames
tell application appName to repeat with aWindow in (get windows whose miniaturized is true)
tell aWindow to try
get it's properties -- see event log
set the end of windowsInDock to "window " & it's index & " of application " & quoted form of appName
on error errmess -- ignore errors
log errmess
end try
end repeat
end repeat
choose from list windowsInDock with prompt "Miniaturized windows:" with empty selection allowed
答案 1 :(得分:2)
这是一个适用于所有应用程序的脚本,至少在我的系统上。
试试这个
set windowsInDock to {}
tell application "System Events"
repeat with this_app in (get processes whose background only is false and windows is not {}) --get applications with 1+ window
set windowsInDock to windowsInDock & (get windows of this_app whose value of its attribute "AXMinimized" is true)
end repeat
end tell
return windowsInDock