2012-04-15 76 views
1

我需要为我的AppleScript PROGRAME一些帮助。AppleScript的 - 列出所有隐藏的窗口在码头 - 微型

我想列出所有打开,并在Dock中的窗口,所以我想这:

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

** 1)**请勿[复制你的问题(http://stackoverflow.com/questions/10155694/applescript-get-status-of-windows-visible如果您没有收到任何回复,请在“码头”或“码头”中)。相反,您可以编辑您的问题,使其碰到* active *选项卡的顶部。 ** 2)**'exists'属性仅用于别名引用。 ** 3)**在'将a&w小型化到windowInDock'的末尾(变量“a”没有被定义)这一行有语法错误,所以你的代码甚至不应该运行。如果您需要进一步的帮助,请询问。 :) – fireshadow52 2012-04-15 18:21:53

+0

好的谢谢! 'a'是一个分隔符。我已经忘记了我的复制/粘贴中的声明。所以'a'被声明为'set a to“@@ ## @@”'。我需要知道重复循环中的“w”是否在码头中。我找不到任何解决方案,你能帮助我吗? – Tokytok 2012-04-15 18:52:37

+0

看看Red_Menace的回答。他似乎在AppleScript上比我流利得多,嘿(他的回答为+1)。 – fireshadow52 2012-04-15 23:27:27

回答

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 
+0

哪个系统/ AppleScript版本是这样的?在我的OS X 10.6.8 + AppleScript 2.1.2上,'window'没有'smallaturized'或'index'属性。 – fanaugen 2012-04-16 14:46:51

+0

我正在运行Lion,但该脚本示例也在Snow Leopard中运行。当然,这取决于在任何给定应用程序中实现的功能(例如,BBedit窗口没有小型化属性)以及应用程序是否可编写脚本(预览)。我只是改变了OP的脚本来移动系统事件的属性,但没有太多的错误检查完成,所以它看起来像让窗户失败,如果有一些没有小型化的属性(我只测试了几个默认应用程序)。 – 2012-04-16 15:19:42

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 
+1

请注意,需要在系统偏好设置中启用辅助设备Access。 – kopischke 2013-06-13 20:49:28

+0

上述代码不在小牛队(10.9.2)中运行:'系统事件发生错误:无法获取每个进程的仅背景= false且每个窗口≠{} .' – 2014-04-02 03:19:33