applescript:从一组候选名称中告诉运行应用程序



我们已经发布了几个不同版本的应用程序。它们具有相似的名称 - foo basic foo deluxe foo retro 等。(这不是我的想法!)一些用户安装了这些应用程序中的一个以上,但是只能运行一个。

所有应用程序都支持同一AppleScript词典。我需要一个applescript来脚本脚本运行的应用程序来做工作。我该怎么做?

我使它起作用。它需要几件:

  • 获取运行应用程序的名称。您可以使用System Eventsprocesses或否则do shell script "ps …"进行此操作,无论您认为在您的情况下都会更可靠。
  • 然后,使用的术语您的 mac上的一个应用程序,您可以
  • *告诉 应用程序 appName…,前提是您有
  • 将您的脚本保存为应用程序,因此已经被编译了。

这是一些代码。我正在使用的脚本尚未诉诸系统事件,因此为了避免新用户的系统偏好旅行的痛苦,我选择使用/bin/ps……

set appName to runningAppWithBaseName("Foo")
using terms from application "Foo Deluxe" -- an app on your Mac
    tell application appName
       (* whatever code you want here *)
    end tell
end using terms from
on runningAppWithBaseName(baseName)
    set command to "/bin/ps -eo args | grep " & baseName & " | grep -v grep"
    (* The "grep -v grep" is to exclude the grep process itself from the results. *)
    try 
        set fullPathOfRunningApp to do shell script command
    end try
    (* Here, given the fullPathOfRunningApp and your list of candidate app names, *)
    (* insert  code to determine the name of the running app. *)
    return nameOfRunningApp
end runningAppWithBaseName

相关内容

最新更新