2013-03-01 95 views
7

我正在尋找一個解決方案來枚舉安裝鍵(Mac)OS X系統上的所有應用程序,即有LaunchServices註冊的所有應用程序軟件包的基本問題。枚舉在OS X上所有安裝的程序

簡單的方法沒有奏效

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

目前我使用的lsregister -dump | grep -E '^.*[ \\t]*path:[ \\t]+(\/.*)$' | grep -Eo '\/.*'輸出,這有幾個問題:用換行

  • .app束(\n,這是有效的在UNIX上)沒有被正確處理(這個問題將是寫作可以解決一個合適的解析器)
  • lsregister不能正確處理奇怪的文件名(例如包含RTL mark)。 lsregister似乎忽略了名稱中帶有RTL標記的文件。 如果需要,可以通過運行以下命令在其名稱中創建一個包含RTL的文件。

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

    這樣做了以後,lsregister -dump | grep ThisIsAWeird透露它。但是當你右鍵點擊一個文本文件並轉到「Open With」時,你會發現LaunchServices和Finder仍然支持該文件。 see yourself

簡單枚舉所有文件/Applications和其他目錄不起作用,因爲LaunchServices在任意文件夾感知應用程序包的,我也需要這些應用程序。

,我沒有去上班

顯然其他計算策略,有一個名爲_LSFindApplications這不正是我需要做一個私有的API函數,但我不能讓它的工作,並沒有發現任何互聯網上的官方文件。 (證明它存在:nm /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices | grep __LSFindApplications$

UPDATE:system_profiler方法也似乎不工作

直到現在我雖然由@Anoop建議system_profiler方法作品,但今天我發現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 
+1

我知道這是可能的,因爲RCDefaultApp這樣做,但我不知道如何。 – zneak 2013-03-01 18:13:13

回答

4

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

我正在尋找一個解決方案來枚舉安裝鍵(Mac)OS X系統上的所有應用程序,即有LaunchServices註冊的所有應用程序軟件包。

這些都是不一樣的東西。在LaunchServices上註冊的應用程序包是lsregister -dump的輸出。這與「安裝的所有應用程序」不同。沒有確切的查詢「安裝的所有應用程序」。 OS X甚至沒有這樣的概念。

system_profiler輸出相當於什麼射燈知道。這不完全是已安裝應用程序的完整列表,並且在幾種情況下可能不正確。例如,Spotlight可能已被禁用,或者它可能尚未完成首次掃描。 (如果Spotlight已完成其第一次掃描,則沒有支持的方式;雷達15177626.)

還有pkgutil --pkgs這將爲您提供額外的「已安裝的東西」。它也不完整,並可能列出未安裝的東西。

您還可以使用mdfind走整個磁盤,看看自己什麼叫應用程序。這很有效,但速度很慢。

您還可以使用locate .app | grep '\.app$'如果定位數據庫是最新的,你只需要捆綁的應用程序,這是非常有效的。

我在WWDC蘋果問這個。沒有簡單的支持答案。打開雷達。你可以問欺騙15177489.

1

如何找到使用可可應用程序/代碼爲here

另外,您可能可以使用system_profiler -xml SPApplicationsDataType,然後解析生成的XML數據以獲取您感興趣的應用程序。

+0

今天發現'lsregister'仍然比'system_profiler' :-(。 – 2013-10-08 17:42:51

1

在終端:

system_profiler SPApplicationsDataType > list_of_all_apps.txt

...的system_profiler查詢的輸出寫入到文本文件。