2013-03-01 14 views
7

problema di base

Sto cercando una soluzione per enumerare tutte le applicazioni installate su un (Mac) del sistema OS X, vale a dire tutte le applicazioni in bundle registrati LaunchServices.enumerare tutte le applicazioni installate sul OS X

approccio semplice che non ha funzionato

(Si prega di notare: lsregister possono essere trovati sotto /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister).

Attualmente sto usando l'output di lsregister -dump | grep -E '^.*[ \\t]*path:[ \\t]+(\/.*)$' | grep -Eo '\/.*', che ha qualche problema:

  • .app fasci con a capo (\n, valida su UNIX) non vengono gestiti correttamente (Questo problema sarebbe risolvibile da scrittura un parser appropriato)
  • lsregister non gestisce correttamente il nome file (ad esempio contenente RTL mark). lsregister sembra ignorare i file con il marchio RTL nel loro nome. Se lo si desidera, è possibile creare un file con RTL nel suo nome eseguendo il seguente comando.

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

    Dopo aver fatto questo, sarà lsregister -dump | grep ThisIsAWeirdnon rivelarlo. Ma quando si fa clic con il pulsante destro su un file di testo e si passa a "Apri con", i servizi di avvio e il Finder continueranno a supportare tale file. see yourself

Basta enumerare tutti i file in /Applications e altre directory non funziona perché LaunchServices è a conoscenza di pacchetti applicativi in ​​cartelle arbitrarie e ho anche bisogno di queste applicazioni.

Altro approch che io non sono riuscito a lavorare

A quanto pare, c'è una funzione API privata chiamata _LSFindApplications che fa esattamente quello che devo fare, ma non riesco a farlo funzionare e non ha trovato alcuna documentazione non ufficiale su internet. (La prova esiste: nm /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices | grep __LSFindApplications$)

UPDATE: metodo system_profiler, inoltre, non sembra funzionare

Fino ad ora ho anche se il metodo system_profiler come suggerito da @Anoop funziona ma oggi ho scoperto che lsregister raccoglie ancora su più binari. Alcuni o mancanti su tutte le macchine, alcuni sembrano mancare solo in system_profiler quando hai montato un volume esterno con un'altra installazione di OS X. Ecco un elenco di cosa manca nell'output di system_profiler (ma è presente in lsregister) su uno dei miei macchine

/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

So che questo è possibile perché RCDefaultApp lo fa ma non so come. – zneak

risposta

4

In primo luogo, la richiesta non è giusto:

Sto cercando una soluzione per enumerare tutte le applicazioni installate su un (Mac) del sistema OS X, vale a dire tutte le applicazioni in bundle registrati LaunchServices.

Questi non sono la stessa cosa. I pacchetti di applicazioni registrati con LaunchServices sono l'output di lsregister -dump. Non è la stessa cosa di "tutte le applicazioni installate". Non esiste una query esatta per "tutte le applicazioni installate". OS X non ha nemmeno davvero un concetto del genere.

L'output di system_profiler è equivalente a ciò che Spotlight conosce. Questo non è esattamente l'elenco completo delle applicazioni installate e potrebbe non essere corretto in diversi casi. Spotlight potrebbe essere stato disabilitato, per esempio, o potrebbe non aver completato la sua prima scansione. (Non esiste un modo supportato per chiedere a Spotlight se ha terminato la prima scansione: radar 15177626.)

C'è anche pkgutil --pkgs che fornirà ulteriori "cose ​​installate". Anche questo non è completo e potrebbe elencare cose che non sono installate.

È anche possibile utilizzare mdfind per percorrere l'intero disco e vedere cosa chiama se stesso un'applicazione. Questo è piuttosto efficace, ma lento.

È inoltre possibile utilizzare locate .app | grep '\.app$' che è piuttosto efficace se il database di individuazione è aggiornato e si desidera solo pacchetti di app.

Ho chiesto informazioni su Apple al WWDC. Non esiste una risposta semplice e supportata. Apri un radar. Si può chiedere di ingannare 15177489.

1

Che dire di trovare usando Cocoa application/codice come fatto here.

Inoltre, è possibile utilizzare system_profiler -xml SPApplicationsDataType e analizzare i dati XML risultanti per ottenere solo le applicazioni a cui si è interessati.

+0

abbiamo scoperto oggi che "lsregister" continua a raccogliere più di 'system_profiler' :-(. –

1

nel terminale:

system_profiler SPApplicationsDataType > list_of_all_apps.txt

... scrive output della query system_profiler a tale file di testo.

Problemi correlati