且构网

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

枚举OS X上所有已安装的应用程序

更新时间:2023-10-11 20:37:04

首先,您的要求不太正确:

First, your request is not quite right:

我正在寻找一种解决方案,以枚举安装在(Mac)OS X系统上的所有应用程序,即已向LaunchServices注册的所有应用程序包.

I'm looking for a solution to enumerate all applications installed on a (Mac) OS X system, i.e. all application bundles registered with LaunchServices.

这些不是一回事.向LaunchServices注册的应用程序捆绑包是lsregister -dump的输出.这与已安装所有应用程序"不同.没有确切的查询已安装所有应用程序". OS X甚至根本没有这样的概念.

Those are not the same thing. The application bundles registered with LaunchServices is the output of lsregister -dump. That is not the same thing as "all applications installed." There is no exact query for "all applications installed." OS X does not even really have such a concept.

system_profiler的输出与Spotlight知道的等效.那不完全是已安装应用程序的完整列表,并且在某些情况下可能不正确.例如,Spotlight可能已被禁用,或者可能尚未完成第一次扫描. (没有支持的方式来询问Spotlight是否已完成第一次扫描;雷达15177626.)

The output of system_profiler is equivalent to what Spotlight knows about. That's not exactly the full list of installed applications, and may not be correct in several cases. Spotlight may have been disabled, for instance, or it may not have completed its first scan. (There is no supported way to ask Spotlight if it has finished its first scan; radar 15177626.)

还有pkgutil --pkgs,它将为您提供其他已安装的物品".它也不完整,可能会列出未安装的东西.

There is also pkgutil --pkgs which will provide you additional "installed things." It isn't complete either, and may list things that are not installed.

您还可以使用mdfind遍历整个磁盘,并查看将其称为应用程序的内容.这很有效,但是很慢.

You can also use mdfind to walk the whole disk and see what calls itself an application. This is pretty effective, but slow.

您还可以使用locate .app | grep '\.app$',如果locate数据库是最新的并且您只需要应用程序捆绑包,这将非常有效.

You can also use locate .app | grep '\.app$' which is pretty effective if the locate database is up to date and you only want app bundles.

我在WWDC上问了苹果这件事.没有简单的受支持的答案.打开雷达.您可以要求欺骗15177489.

I asked Apple about this at WWDC. There is no simple, supported answer. Open a radar. You can ask to dupe 15177489.