AppleScript最小化所有可见窗口非常慢。如何加快速度?

时间:2011-12-23 21:03:24

标签: performance applescript minimize

在全新(2011秋季)13“MacBook Pro 2.4GHz上运行OS X Lion 10.7.2。

我在下面找到了AppleScript,它最大限度地减少了所有可见窗口,但它作为一个应用程序运行速度非常慢。

当它在AppleScript编辑器中打开并单击“运行”时,它的工作速度足够快意味着它立即启动,几秒钟后所有窗口都被最小化。但是当我将它保存为应用程序时,我可以启动应用程序,它可以在Windows开始最小化之前5到10秒。

如何加快这个脚本的速度,让它运行得更快?我发现以下文章讨论了使用“which”子句,但老实说不知道如何在这个脚本中使用它: http://www.mactech.com/articles/mactech/Vol.12/12.05/ASPerformance/index.html

原始AppleScript位于此处: https://apple.stackexchange.com/questions/26811/truly-minimize-all-windows

这是脚本:

tell application "System Events"

set theButtons to {}

repeat with theApplication in application processes

  repeat with theWindow in windows of theApplication

    repeat with theButton in buttons of theWindow

      if ((description of theButton) is "minimize button") then

        set theButtons to theButtons & {theButton}

      end if

    end repeat

  end repeat

end repeat

repeat with theButton in theButtons

  click theButton

end repeat

end tell

编辑:(已解决)

感谢Red_Menace让我朝着正确的方向前进!

我认为这将是我使用的脚本,直到我弄清楚如何在xcode中执行此操作:

tell application "System Events"
  repeat with appProc in (every application process whose visible is true)
    click (first button of every window of appProc whose role description is "minimize button")
  end repeat
end tell

编辑:作为应用程序运行

不确定原因,但是当您将AppleScript保存为应用程序时,它甚至在启动之前需要5到10秒,而不是将其保留为脚本。将其保留为脚本的问题在于您无法为脚本文件创建别名,因为它将在编辑器中打开脚本文件而不是运行它。解决方案:启动Automator并选择New Application。然后查找名为Run AppleScript的Action,并将其拖到右侧。将AppleScript复制并粘贴到此框中并保存,现在您的应用程序运行速度与AppleScript一样快,您可以在桌面上创建别名。

编辑:2015年3月:找到了一个更好的解决方案:更好的触摸工具(它是免费的)有一个“隐藏所有Windows”的快捷方式,就像Windows一样,它实际上最小化并隐藏所有打开的窗口(不像OSX默认的只是将它们从屏幕上移开)。您可以将其分配给任何键盘组合或鼠标移动...我已将其分配给“OPTION_KEY + Move_Mouse_Into_Lower_Left_Corner”。

2 个答案:

答案 0 :(得分:2)

你发布的脚本效果不是很好,因为它得到每个进程(这可以通过获取可见的应用程序进程来修复),并且重复循环的项是动态的,可能会导致窗口未最小化(这可以通过显式获取UI项目来修复)。话虽如此,我认为大部分延迟是应用程序首次启动时,因此您可以尝试从脚本菜单运行脚本。

至于其子句,它可能类似于:

tell application "System Events"
    set theResults to get buttons of (windows of (application processes whose visible is true)) whose description is "minimize button" -- a list of visible applications, containing a list of windows, containing a list of (one) buttons

    repeat with anApp in theResults
        if contents of anApp is not in {} then -- windows are open
            repeat with eachWindow in (items of anApp)
                click first item of eachWindow -- only the one minimize button
            end repeat
        end if
    end repeat
end tell

答案 1 :(得分:0)

我在http://murphymac.com/hide-everything/上找到了一个脚本,它的工作方式就像是在Sierra的

上的魅力
tell application "Finder"
set visible of every process whose visible is true and name is not "Finder" to false
close every window 
end tell
相关问题