-->

枚举在OS X上所有安装的程序(Enumerate All Installed Applicatio

2019-07-20 19:15发布

基本问题

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

简单的方法没有奏效

(请注意: lsregister下可以找到/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister )。

目前我使用的输出lsregister -dump | grep -E '^.*[ \\t]*path:[ \\t]+(\/.*)$' | grep -Eo '\/.*' lsregister -dump | grep -E '^.*[ \\t]*path:[ \\t]+(\/.*)$' | grep -Eo '\/.*' lsregister -dump | grep -E '^.*[ \\t]*path:[ \\t]+(\/.*)$' | grep -Eo '\/.*'其中有几个问题:

  • .app捆绑用换行( \n ,这是对UNIX有效)没有被正确处理(这个问题将能够固定通过写一个适当的解析器)
  • lsregister不能正确处理怪异的文件名(如包含RTL标记 )。 lsregister只是似乎忽略了在他们的名字RTL标记文件。 如果你愿意,你可以通过运行下面的命令在其名称中创建RTL文件。

     python -c 'import shutil; shutil.copytree(u"/Applications/TextEdit.app", u"/Applications/ThisIsAWeird\u202EApp.app")' 

    这样,后lsregister -dump | grep ThisIsAWeird lsregister -dump | grep ThisIsAWeird 不会透露它。 但是,当你在一个文本文件,点击右键,进入“打开方式”,你会说LaunchServices和Finder仍然支持该文件。

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

其他计算策略,我没有去上班

显然,有一个名为私有的API函数_LSFindApplications这不正是我需要做的,但我不能让它的工作,并没有在互联网上找到任何非官方的文档。 (证明它的存在: nm /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices | grep __LSFindApplications$

更新:system_profiler方法也似乎不工作

到现在为止我虽然system_profiler由@Anoop建议的方法工作,但今天我发现lsregister仍然拿起更多的二进制文件。 一些或缺少在所有机器上,一些似乎中唯一缺少的system_profiler当你安装一个外部体积OS X.这里的另一个安装的一个列表有什么遗漏在输出system_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

Answer 1:

首先,你的要求是不完全正确:

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

这些都是不一样的东西。 与LaunchServices注册的应用程序包是的输出lsregister -dump 。 那是不一样的东西“已安装的所有应用程序。” 不存在用于精确查询“已安装的所有应用程序。” OS X甚至不真的有这样的概念。

输出system_profiler相当于什么射灯知道。 这不完全安装的应用程序的完整列表,并在一些情况下可能不正确。 焦点可能已被禁用,例如,或者它可能还没有完成第一次扫描。 (有没有支持的方式询问焦点,如果它已经完成了它的第一次扫描;雷达15177626.)

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

您还可以使用mdfind走整个磁盘,看看自己什么叫应用程序。 这是非常有效的,但速度缓慢。

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

我在WWDC苹果问这个。 有没有简单的,支持的答案。 打开雷达。 你可以问欺骗15177489。



Answer 2:

在终端:

system_profiler SPApplicationsDataType > list_of_all_apps.txt

...写system_profiler查询输出到文本文件。



Answer 3:

怎么样找到使用Cocoa应用程序/代码完成这里 。

此外,您可能能够使用使用system_profiler -xml SPApplicationsDataType ,然后解析生成的XML数据,得到的只是你感兴趣的应用。



文章来源: Enumerate All Installed Applications on OS X