How to detect presence of another application?

Discussion in 'Mac Programming' started by frankpuccino, Jul 26, 2010.

  1. frankpuccino macrumors newbie

    Joined:
    Jul 24, 2010
    #1
    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
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Try -[NSWorkspace URLForApplicationWithBundleIdentifier:] and pass in the bundle identifier of the application found in its Info.plist file.
     
  3. frankpuccino thread starter macrumors newbie

    Joined:
    Jul 24, 2010
    #3
    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
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #5
    Not quite as clever, but you could always just grep through the output from "ls /Applications"
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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 (!).
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    Also:
    Code:
    locate lsregister
    
    And try running it with the -dump option.

    More info can be found by googling lsregister.
     
  8. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #8
    And some of us who do know what we are doing place applications in other places.
     
  9. fernandovalente macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #9
    Me for example. Sometimes I leave applications inside the downloads folder #epicfail
     
  10. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #10
    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.
     
  11. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #11
    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.
     
  12. frankpuccino thread starter macrumors newbie

    Joined:
    Jul 24, 2010
    #12
    kainjow,

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

    Frank
     
  13. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #13
    I used gdb through Xcode (New Project > Empty Project > Add New Custom Executable).
     

Share This Page