 |
 |
Getting available applications
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
Check LaunchServices/LaunchServices.h -- IIRC, it provides functions to list all the applications "known" to the system.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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;
}
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|