AppleScript 最小化所有可见窗口的速度非常慢。如何加快速度?
在全新(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您发布的脚本实际上并不能很好地工作,因为它获取每个进程(这可以通过仅获取可见的应用程序进程来修复)并且重复循环的项目是动态的,这可能会导致未最小化的窗口(这可以通过显式获取 UI 项目来修复)。话虽如此,我认为大部分延迟是在应用程序首次启动时发生的,因此您可以尝试从脚本菜单运行脚本。
至于 who 子句,它可以是这样的:
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:
我在以下位置找到了一个脚本: http://murphymac.com/hide-everything/ 有效就像 macOS Sierra 上的魅力一样
I've found a script on: http://murphymac.com/hide-everything/ which works like a charm on macos Sierra