所以我在这里有一个非常基本的 Applescript,它基本上隐藏了我所有与社交网络相关的应用程序,然后还有一个类似的应用程序可以取消隐藏它们。问题是,如果其中一个应用程序没有运行,那么整个应用程序都会在该行停止,并且不会将该行下方的应用程序设置为隐藏。
这是脚本:
tell application "System Events" to set visible of process "Twitter" to false
tell application "System Events" to set visible of process "Wedge" to false
tell application "System Events" to set visible of process "Facebook" to false
tell application "System Events" to set visible of process "Adium" to false
tell application "System Events" to set visible of process "Messages" to false
我这样做是错误的吗?我是否必须检查它们中的每一个是否首先运行,或者是否有某种方法可以让它继续执行脚本?
编辑:使用此脚本体验同样的事情,我使用 Alfred 热键退出特定应用程序并在我下班时启动屏幕保护程序:
tell application "Adium" to quit
tell application "Messages" to quit
tell application "1Password" to quit
tell application "iTunes" to quit
tell application "ScreenSaverEngine" to activate
所以基本上如果 iTunes - 例如 - 没有运行,那么屏幕保护程序将不会启动,但该行之前的 3 个应用程序将全部退出。