Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Getting available applications

Getting available applications
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jan 22, 2004, 09:35 AM
 
Anyone know how to access the stored list of available applications? Basically everything at /Applications/ and a few other places. Thanks!
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 22, 2004, 12:54 PM
 
What other places? I'm not aware of any way to do this other than searching a bunch of standard paths that may contain applications. You might want to take a look at NSPathUtilities.h in the Foundation Framework to see how you can get a list of search paths, and just look for bundles or .apps or read plists. Of course, Mac OS allows users to put applications anywhere they want them, so you might not find everything this way.
     
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jan 22, 2004, 01:59 PM
 
Ok, I will check out NSPathUtilities. I mainly want the ones located in /Applications/ Thanks!
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 22, 2004, 02:29 PM
 
In that case, you can just grab the search path (don't hard code a path to "/Applications") and look for everything in that folder, or in nested folders, that has a .app extension. Be careful not to look inside of the .apps though -- they are also folders and they may contain other applications that you probably don't want to include.
     
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jan 22, 2004, 02:47 PM
 
Ok, I just checked out what I can use in NSPathUtilities. Care to enlighten me on grabbing an entire folder?
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 22, 2004, 02:51 PM
 
You can use NSSearchPathForDirectoriesInDomains to find the paths you want to search, and methods in the NSFileManager class to look at directory contents. eg:
Code:
- (NSDirectoryEnumerator *)enumeratorAtPath: (NSString *)path
     
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jan 22, 2004, 03:03 PM
 
How about this:

NSString *directory;

NSSearchPathDirectory dir;
directory = [dir NSApplicationDirectory];

I cannot test it right now because I am at work... Does it look right though?
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Jan 22, 2004, 03:09 PM
 
Check LaunchServices/LaunchServices.h -- IIRC, it provides functions to list all the applications "known" to the system.
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jan 22, 2004, 03:18 PM
 
Isnt that carbon? I am trying to keep the app all cocoa... Dont know if it matters though.
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 22, 2004, 03:18 PM
 
I thought LaunchServices could only discover document bindings? Anyway, I figured there's probably a better way than using Foundation/PathUtilities.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jan 22, 2004, 03:36 PM
 
If you are not looking for constant run-time listing, you could also look at the system_profiler command line app. If you just run it it will spew a lot of information to stdout, including a list of applications.
     
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jan 22, 2004, 04:17 PM
 
I need constant runtime updating. I think the code I posted earlier will find what I need. If not I am sure I can find the way to make it work.
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 22, 2004, 04:43 PM
 
NSSearchPathForDirectoriesInDomains is a function, not an object. I should've given you the documentation URL:

http://developer.apple.com/documenta...00055/BCIJCEFC

The code you want to start off with is probably something like this:

Code:
NSFileManager * fm = [NSFileManager defaultManager]; NSArray * paths = NSSearchPathForDirectoriesInDomains (NSApplicationDirectory, NSLocalDomainMask | NSUserDomainMask, TRUE); NSEnumerator * pathEnum = [paths objectEnumerator]; NSString * path, * file; NSDirectoryEnumerator * dirEnum; while (path = [pathEnum nextObject]) { dirEnum = [fm enumeratorAtPath: path]; while (file = [dirEnum nextObject]) { if ([[file pathExtension] isEqualToString:@"app"]) // do what you want with it here } }
You can access Carbon in a Cocoa app tho, so if LaunchServices has a method to call that would be a much easier way to do it.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jan 23, 2004, 06:39 PM
 
Originally posted by Rickster:
Check LaunchServices/LaunchServices.h -- IIRC, it provides functions to list all the applications "known" to the system.
Last I checked, that was SPI. Pretty easy to use, though. Normal disclaimer about using undocumented, private functions applies.
Code:
#include <ApplicationServices/ApplicationServices.h> #include <CoreFoundation/CoreFoundation.h> extern OSStatus _LSCopyAllApplicationURLs(CFArrayRef *array); int main(int argc, char *argv[]) { CFArrayRef array; _LSCopyAllApplicationURLs(&array); CFShow(array); return 0; }
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2