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

发布于 2024-12-22 11:44:07 字数 2035 浏览 2 评论 0原文

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

我发现了下面的 AppleScript,它可以最小化所有可见窗口,但作为应用程序运行速度非常慢。

当它在AppleScript 编辑器,我单击“运行”,它运行得足够快,这意味着它会立即启动,几秒钟后所有窗口都会最小化,但是当我将其另存为应用程序时,我可以启动该应用程序,并且它可以是 5 到 5 秒。在 Windows 开始最小化之前 10 秒,

我怎样才能加快这个脚本的速度,使其运行得更快?脚本: http://www.mactech.com/articles/ mactech/Vol.12/12.05/ASPerformance/index.html

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

这是脚本:

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 并选择“新建应用程序”。然后查找名为“运行 AppleScript”的操作,并将其拖到右侧。将 AppleScript 复制并粘贴到此框中,然后保存,您现在就拥有了一个与 AppleScript 一样快运行的应用程序,并且您可以在桌面上创建别名。

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

Running OS X Lion 10.7.2 on a brand new (fall 2011) 13" MacBook Pro 2.4GHz.

I found the AppleScript below, which minimizes all visible windows, but it runs very very slow as an application.

When it is open in the AppleScript Editor and I click Run, it works fast enough meaning it starts right away, and after a few seconds all the windows are minimized. But when I save it as an application, I can start the application and it can be 5 to 10 seconds before the windows even start to be minimized.

How can I speed this script up, so it runs faster? I found the following article that talks about using the "whose" clause, but honestly have no idea how to use it in this script:
http://www.mactech.com/articles/mactech/Vol.12/12.05/ASPerformance/index.html

The original AppleScript is found here:
https://apple.stackexchange.com/questions/26811/truly-minimize-all-windows

Here is the script:

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

EDIT: (RESOLVED)

Thanks to Red_Menace who got me going in the right direction!

I think this will be the script I use, until I figure out how to do this in 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

EDIT: Running as Application

Not sure why, but when you save an AppleScript as an application it takes 5 to 10 seconds before it even starts, as compared to keeping it as a script. The problem with keeping it as a script is that you cannot create an alias to the script file because it will open the script file up in the editor instead of running it. The solution: Start up Automator and choose New Application. Then look for Action called Run AppleScript, and drag it over to the right hand side. Copy and Paste your AppleScript into this box, and save it and you now have an application that runs as fast as the applescript did, and you can create an alias on your desktop.

EDIT: March 2015: Found a better solution for this: Better Touch Tool (it's free) has a "Hide All Windows" shortcut that works like Windows, where it actually minimizes and hides all open windows (unlike OSX default of just moving them off the screen). You can assign it to any keyboard combo or mouse movement... I have assigned it to "OPTION_KEY + Move_Mouse_Into_Lower_Left_Corner".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜灵血窟げ 2024-12-29 11:44:07

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

至于 who 子句,它可以是这样的:

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

Your posted script doesn't really work that well, since it gets every process (this can be fixed by just getting the visible application processes) and the items for the repeat loops are dynamic, which can result in windows that are not minimized (this can be fixed by explicitly getting the UI items). With that said, I think the majority of the delay is when the application first starts up, so you might try running your script from the Scripts Menu instead.

As for the whose clause, it could go something like:

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
悲喜皆因你 2024-12-29 11:44:07

我在以下位置找到了一个脚本: http://murphymac.com/hide-everything/ 有效就像 macOS 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

I've found a script on: http://murphymac.com/hide-everything/ which works like a charm on macos 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文