Mac How to detect presence of another application?

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
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
3
Try -[NSWorkspace URLForApplicationWithBundleIdentifier:] and pass in the bundle identifier of the application found in its Info.plist file.
 

frankpuccino

macrumors newbie
Original poster
Jul 24, 2010
29
0
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
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
3
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

Moderator emeritus
Jun 15, 2000
7,958
3
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 (!).
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
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.
 

mrbash

macrumors 6502
Aug 10, 2008
251
1
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.
 

frankpuccino

macrumors newbie
Original poster
Jul 24, 2010
29
0
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
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
3
I used gdb through Xcode (New Project > Empty Project > Add New Custom Executable).