让 Applescript 等待应用程序关闭后再运行 shell 脚本

让 Applescript 等待应用程序关闭后再运行 shell 脚本

我使用 Applescript 制作了一个小程序,它会打开一个应用程序,然后在加载后运行一个卸载 Spotlight 的 shell 脚本。我需要让它等我使用完相关应用程序后再运行另一个 shell 脚本来再次加载 Spotlight。

我的代码目前看起来像:

set appname to “Applications/Cubase 5.app”
    tell application appname to launch
        repeat until application appname is running    
        delay 1
        end repeat
if application appname is running then
    do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
    end if
activate appname

我什么都试过了,但还是搞不清。我用我有限的知识找到并修改了这个脚本,但不明白它是如何工作的。

我需要添加什么代码才能让它等待我退出应用程序以运行我知道的第二个 shell 脚本:

do shell script "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges

哪个重新加载 Spotlight?

我想出了下面的编译方法,但没有按预期运行:

set appname to “Applications/Cubase 5.app”
    tell application appname to launch
        repeat until application appname is running    
        delay 1
        end repeat
if application appname is running then
    do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
    end if
activate appname
    repeat until application appname is not running
    delay 1
    end repeat
if application is not running then
    do shell script "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
end if

给了我错误无法运行应用程序。我知道缺少了一些东西,但不知道是什么。

我对 Apple 和 Applescript 都很陌生,如能得到答复我将非常感激。

答案1

你想测试不是跑步

set appname to “Applications/Cubase 5.app”
    tell application appname to launch
        repeat until application appname is not running    
            delay 1
        end repeat
if application appname is running then
    do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist" password "YOUR_PASSWORD" with administrator privileges
end if
activate appname

相关内容