且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当我有文件路径时,如何检查应用程序是否正在运行?

更新时间:2022-11-06 17:51:33

我们在 Mac 上有很多工具,您通常可以找到解决方案.在您的情况下,我同意您不能过滤应用程序文件".您可能只能过滤字符串、数字或布尔值.

We have lots of tools on the Mac and you can usually find a solution. In your case I agree that you cannot filter on the "application file". You can probably only filter on strings, numbers, or bools.

然而,我们确实有其他工具,例如命令行,并且我们也可以访问objective-c 方法.这是一个命令行方法...

However we do have other tools such as the command line and we also have access to objective-c methods. Here's a command line method...

set applicationPosixPath to "/Applications/Utilities/AppleScript Editor.app"

try
    do shell script "/bin/ps -ef | grep " & quoted form of applicationPosixPath & " | grep -v grep"
    return "application is running"
on error
    return "application is not running"
end try