Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

frankpuccino

macrumors newbie
Original poster
Jul 24, 2010
29
0
I'm a programmer about to deploy a Mac OS X application.

What is the best way for me to detect on a Mac OS X box
that a particular application is installed?

Suppose I want to see if the user has Little Snitch.

My feeling is that checking for the existence of
"Little Snitch Configuration.app" in the /Applications directory
is not the best way.

My feeling is also that using an NSTask to call
"system_profiler -detailLevel full" and then parsing
the list of applications is also not optimal.

Thank you.

Frank
 
Try -[NSWorkspace URLForApplicationWithBundleIdentifier:] and pass in the bundle identifier of the application found in its Info.plist file.
 
kainjow,

Thanks for your reply. It seems to work.

btw, do you know how to get a list of all installed applications?

I can't see a method in NSWorkspace that allows this.

Frank
 
I don't see anything. "system_profiler SPApplicationsDataType -xml" with NSTask might be your best option.

EDIT: I just ran system_profiler in the debugger and it appears they're using the Spotlight API to find apps, which makes sense. Check out NSMetadataQuery.
 
Not quite as clever, but you could always just grep through the output from "ls /Applications"

Some of us use ~/Applications as well :). And a lot of people I know who don't really know much about computers put applications all over the place, like their Desktop (!).
 
You could always ask 'system_profiler' to gather the information for you thru the use of 'popen'.

man system_profiler
system_profiler -listDataTypes

'system_profiler SPApplicationsDataType' will give you a list of "Applications" that are installed on the computer. Looking thru the list of information types you can probably come up with other software types you'd like to know about.

Edit:
If you're looking for running applications the Process Manager API still works although not for BSD daemons you'd need to use the ''stat' (I think, to early for me) function.
 
Use Spotlight

You should be able to use Spotlight's API to see if a particular program is on the system. You can create a query and then search through the results.

I haven't done this, but the above approach seems the most logical. Here is the link to Apple's developer site.
 
I don't see anything. "system_profiler SPApplicationsDataType -xml" with NSTask might be your best option.

EDIT: I just ran system_profiler in the debugger and it appears they're using the Spotlight API to find apps, which makes sense. Check out NSMetadataQuery.

kainjow,

Did you actually attach gdb to system_profiler
or did you use Dtrace to figure this out?

Frank
 
I used gdb through Xcode (New Project > Empty Project > Add New Custom Executable).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.