我能想到的与我最相关的例子是能够在关闭iTunes时关闭last.fm应用程序。我经常忘记关闭last.fm,我觉得它很烦人。我确定还有其他用途......
答案 0 :(得分:1)
是的,你可以。
在我的Blog thecocoaquest上,我有两个帖子来涵盖这个。
第一篇文章向您展示了使用AppleScript和使用启动代理执行此操作的方法。
Applescript – Quit or Launch Application if another is or is not running
以下是其中一个例子:
如果我有一个运行第二个应用程序的应用程序将启动,并且将在第一个应用程序运行时一直运行。
或者当我退出第一个应用程序时,第二个应用程序也将退出
#!/usr/bin/osascript
#Copyright Mark Hunte 2012
#http://www.markosx.com/thecocoaquest/kill-one-application-if-another-is-not-running-applescript
set appMustBeRunning to "xcode"
set appToKill to "Snippets"
tell application "System Events"
set appMustBeRunningID to (unix id of processes whose name is appMustBeRunning)
set appToKillID to (unix id of processes whose name is appToKill)
end tell
if appMustBeRunningID is {} then
try
tell application "Snippets" to quit
end try
else if appToKillID is {} then
tell application "Snippets" to launch
end if
第二篇文章是一个修订版,展示了如何添加多个主文件和版本。奴隶申请
Applescript – Quit or Launch Application script.. ( Revised )
如果您只想将Applescript作为应用程序运行,还有一个脚本。