简体   繁体   English

用于从其包标识符获取程序路径的Shell脚本

[英]Shell script for getting the path to program from its bundle identifier

In a shell script I need to know the path to a program from its bundle identifier. 在shell脚本中,我需要从其包标识符中知道程序的路径。

The last answer of this SO question almost answers my question: 这个SO问题的最后一个答案几乎回答了我的问题:

Eg for getting the path to XCode the idea is to launch this AppleScript one liner: 例如,为了获得XCode的路径,我们的想法是启动这个AppleScript one liner:

osascript -e "POSIX path of (path to application id \"com.apple.dt.Xcode\")"

This displays the path, but it also launches the Xcode program. 这将显示路径,但它也会启动Xcode程序。

Does anybody have an idea how to display the path without launching the program? 有没有人知道如何在启动程序的情况下显示路径?

Any other method than using AppleScript is of course welcome. 除了使用AppleScript之外的任何其他方法当然都是受欢迎的。

You can use the Finder to get the path: 您可以使用Finder获取路径:

osascript -e 'tell application "Finder" to POSIX path of ((application file id "com.apple.dt.Xcode") as alias)'

Or, you can use a method of the NSWorkspace class ( macOS 10.6+ ): 或者,您可以使用NSWorkspace类的方法( macOS NSWorkspace ):

/usr/bin/python -c 'from AppKit import NSWorkspace; print NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.apple.dt.Xcode").path()'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM