Macos 枚举OS X上所有已安装的应用程序 基本问题

Macos 枚举OS X上所有已安装的应用程序 基本问题,macos,osx-mountain-lion,launch-services,Macos,Osx Mountain Lion,Launch Services,我正在寻找一种解决方案来枚举(Mac)OS X系统上安装的所有应用程序,即所有注册到的应用程序包 不起作用的简单方法 (请注意:lsregister可在/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister下找到) 目前我使用的是lsregister-dump | grep-E'^.*.[\\t]*路径的输出:[\\t]+(\/.*)$'| g

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

不起作用的简单方法 (请注意:
lsregister
可在
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
下找到)

目前我使用的是
lsregister-dump | grep-E'^.*.[\\t]*路径的输出:[\\t]+(\/.*)$'| grep-Eo'\/.'
,它有一些问题:

  • 带有换行符(
    \n
    ,在UNIX上有效)的
    .app
    捆绑包未正确处理(此问题可通过编写适当的解析器解决)
  • lsregister
    无法正确处理奇怪的文件名(例如,包含)
    lsregister
    似乎忽略了名称中带有RTL标记的文件。 如果需要,可以通过运行以下命令创建名称为RTL的文件

    python -c 'import shutil; shutil.copytree(u"/Applications/TextEdit.app", u"/Applications/ThisIsAWeird\u202EApp.app")'
    
    执行此操作后,
    lsregister-dump | grep thisisaward
    将不会显示它。但当您右键单击文本文件并转到“打开方式”时,您将看到LaunchServices和Finder仍然支持该文件。

简单地枚举
/Applications
和其他目录中的所有文件不起作用,因为LaunchServices知道任意文件夹中的应用程序包,我也需要这些应用程序

我没有去工作的其他方法 显然,有一个名为
\u LSFindApplications
的私有API函数,它正是我需要做的,但我无法让它工作,也没有在internet上找到任何非官方文档。(证明它存在:
nm/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices | grep u LSFindApplications$

更新:system_profiler方法似乎也不起作用 到目前为止,我一直认为@Anoop建议的
system\u profiler
方法有效,但今天我发现
lsregister
仍能提取更多的二进制文件。所有计算机上都有一些或缺失,当您使用另一个OS X安装安装外部卷时,
system\u profiler
中似乎只有一些缺失。下面列出了我的一台计算机上的
system\u profiler
输出中缺失的内容(但存在于
lsregister
):

/Applications/Automator.app/Contents/Resources/Application Stub.app
/Applications/Google Chrome.app/Contents/Versions/30.0.1599.69/Google Chrome Framework.framework/Resources/app_mode_loader.app
/Applications/Google Chrome.app/Contents/Versions/30.0.1599.69/Google Chrome Framework.framework/Resources/crash_report_sender.app
/Applications/Google Chrome.app/Contents/Versions/30.0.1599.69/Google Chrome Helper EH.app
/Applications/Google Chrome.app/Contents/Versions/30.0.1599.69/Google Chrome Helper NP.app
/Applications/Google Chrome.app/Contents/Versions/30.0.1599.69/Google Chrome Helper.app
/System/Library/CoreServices/AddPrinter.app
/System/Library/CoreServices/AirPlayUIAgent.app
/System/Library/CoreServices/AppleFileServer.app
/System/Library/CoreServices/AppleGraphicsWarning.app
/System/Library/CoreServices/AppleScript Runner.app
/System/Library/CoreServices/AppleScript Utility.app
/System/Library/CoreServices/CalendarFileHandler.app
/System/Library/CoreServices/Certificate Assistant.app
/System/Library/CoreServices/CoreLocationAgent.app
/System/Library/CoreServices/CoreServicesUIAgent.app
/System/Library/CoreServices/CoreTypes.bundle
/System/Library/CoreServices/Database Events.app
/System/Library/CoreServices/DiskImageMounter.app
/System/Library/CoreServices/Expansion Slot Utility.app
/System/Library/CoreServices/File Sync.app
/System/Library/CoreServices/FileSyncAgent.app
/System/Library/CoreServices/Folder Actions Dispatcher.app
/System/Library/CoreServices/Folder Actions Setup.app
/System/Library/CoreServices/HelpViewer.app
/System/Library/CoreServices/Image Events.app
/System/Library/CoreServices/Install in Progress.app
/System/Library/CoreServices/Jar Launcher.app
/System/Library/CoreServices/Java Web Start.app
/System/Library/CoreServices/KeyboardSetupAssistant.app
/System/Library/CoreServices/Language Chooser.app
/System/Library/CoreServices/LocationMenu.app
/System/Library/CoreServices/MRTAgent.app
/System/Library/CoreServices/Memory Slot Utility.app
/System/Library/CoreServices/NetAuthAgent.app
/System/Library/CoreServices/Network Diagnostics.app
/System/Library/CoreServices/Network Setup Assistant.app
/System/Library/CoreServices/ODSAgent.app
/System/Library/CoreServices/Pass Viewer.app
/System/Library/CoreServices/Printer Setup Utility.app
/System/Library/CoreServices/RegisterPluginIMApp.app
/System/Library/CoreServices/Screen Sharing.app
/System/Library/CoreServices/SecurityAgent.app
/System/Library/CoreServices/SecurityFixer.app
/System/Library/CoreServices/SocialPushAgent.app
/System/Library/CoreServices/System Events.app
/System/Library/CoreServices/System Image Utility.app
/System/Library/CoreServices/SystemUIServer.app
/System/Library/CoreServices/Ticket Viewer.app
/System/Library/CoreServices/UniversalAccessControl.app
/System/Library/CoreServices/UnmountAssistantAgent.app
/System/Library/CoreServices/UserNotificationCenter.app
/System/Library/CoreServices/VoiceOver.app
/System/Library/CoreServices/ZoomWindow.app
/System/Library/CoreServices/backupd.bundle/Contents/Resources/TMLaunchAgent.app
/System/Library/CoreServices/loginwindow.app
/System/Library/CoreServices/rcd.app
/System/Library/Frameworks/PubSub.framework/Versions/A/Resources/PubSubAgent.app
/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/QuickLookUI.framework/Versions/A/Resources/QuickLookUIHelper.app
/System/Library/Frameworks/QuickLook.framework/Versions/A/Resources/quicklookd.app
/System/Library/PrivateFrameworks/DiskImages.framework/Versions/A/Resources/DiskImages UI Agent.app
/System/Library/Services/AppleSpell.service
/System/Library/Services/ChineseTextConverterService.app
/System/Library/Services/ImageCaptureService.app
/System/Library/Services/OpenSpell.service
/System/Library/Services/SpeechService.service
/System/Library/SocialServices/Facebook.socialplugin
/System/Library/SocialServices/Twitter.socialplugin
/System/Library/SocialServices/Weibo.socialplugin

使用Cocoa应用程序/代码查找如何


此外,您还可以使用
system\u profiler-xml SPApplicationsDataType
,然后解析生成的xml数据,以获得您感兴趣的应用程序。

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

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

这不是一回事。向LaunchServices注册的应用程序包是
lsregister-dump
的输出。这与“所有已安装的应用程序”不同。对于“所有已安装的应用程序”没有确切的查询。OSX甚至没有这样的概念

system\u profiler
的输出相当于Spotlight所知道的内容。这并不是已安装应用程序的完整列表,在某些情况下可能不正确。例如,聚光灯可能已禁用,或者可能尚未完成第一次扫描。(没有支持的方式询问Spotlight是否已完成第一次扫描;雷达15177626。)

还有
pkgutil--pkgs
,它将为您提供额外的“已安装的东西”。它也不完整,可能会列出未安装的东西

您还可以使用
mdfind
浏览整个磁盘,查看什么称自己为应用程序。这很有效,但速度很慢

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

我在WWDC向苹果公司询问了这一点。没有简单的、有支持的答案。打开雷达。您可以要求在终端中复制15177489。

system\u profiler SPApplicationsDataType>列出所有应用程序的列表.txt


。。。将system_profiler查询的输出写入该文本文件

我知道这是可能的,因为RCDefaultApp可以做到这一点,但我也不知道是如何做到的。我今天发现
lsregister
仍然拾取了比
system\u profiler
更多的信息:-(.我对基于
find
mdfind
locate
的方法的问题是,它们将列出安装的应用程序(
XCode.App
)内部使用的.App包。相比之下,即使是
ls-1/applications
)也更接近现实。