我有一个applescript来关闭所有应用程序:
tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder"
repeat with closeall in quitapps
quit application closeall
end repeat
效果很好。它退出所有开放的应用程序。
我的问题是,我想修改这个脚本,只关闭隐藏的应用程序。出于某种原因,苹果隐藏了所有苹果制作的没有活动窗口的应用程序,最终它开始消耗我的内存。
我所想的是,如果我把行whose visible is true
改为whose visible is false
,我就会得到这个结果。
不完全是:
我甚至不知道这扇窗户应该是什么,所以我只点击了“取消”。
又弹出来了。结果是在剧本爆炸之前我得按四下取消键。
在打开可见的应用程序的同时,有没有办法退出所有隐藏的应用程序?
(如果你能解释上面弹出的内容,你就会得到额外的分数。)
如果有区别的话,我正在运行OSX的最新版本。
发布于 2017-07-15 04:51:48
将visible
设置为false会影响没有GUI的所有进程、- even进程/应用程序。如果进程不是应用程序(.app),则会出现应用程序选择器。
添加对background only
的检查,它只影响具有GUI的应用程序。
tell application "System Events" to set quitapps to name of every application process whose visible is true and background only is false and name is not "Finder" ...
发布于 2017-07-18 12:01:13
如果我理解正确的话,你说的是当你按下红色关闭按钮时,它只是关闭应用程序的窗口,而不是应用程序本身,所以它仍然处于打开状态。
在这种情况下,您可以使用我编写的脚本,它似乎运行得完美无缺:
-- Get open apps
tell application "System Events" to set openApps to name of every application process whose background only is false and name is not "Finder"
-- Do this for every open app
repeat with openApp in openApps
tell application openApp
-- Tell application to quit if it doesn't have any open windows
if (count of windows) is less than or equal to 0 then quit
end tell
end repeat
发布于 2017-07-19 23:51:30
OSX不“隐藏”应用程序。它们只是不活动,或者没有打开任何文档。隐藏的应用程序是一个非常具体的过程,通常使用命令-H。应用程序不会以这种方式隐藏自己。
与其尝试关闭没有窗口的应用程序,不如使用文档计数来确定是否关闭应用程序。
tell application "SomeApp" if count of documents = 0 then quit
https://stackoverflow.com/questions/45112708
复制相似问题