Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a Mac OS X application is present

I recall there being a Cocoa framework or AppleScript dictionary to check if an Application bundle with a specific name is installed at all, anywhere on the computer.

How do I do this? Either Cocoa, AppleScript, or command line are useful to me.

like image 686
Steve McLeod Avatar asked Mar 01 '11 14:03

Steve McLeod


People also ask

How do you check if a program is running on a Mac?

Open a Finder window and navigate to Applications>Utilities. Double-click Activity Monitor. In the main window, you will see a list of processes with strange names. This is everything running on your Mac right now.

How do I know what software is on my macOS X?

Which macOS version is installed? From the Apple menu  in the corner of your screen, choose About This Mac. You should see the macOS name, such as macOS Monterey or macOS Big Sur, followed by its version number. If you need to know the build number as well, click the version number to see it.

How can you tell if a Mac is a suspicious process?

Look for any suspicious processes that are running on your Mac. On the menu bar, click Go, and then select Utilities. Double-click Activity Monitor. Review the list for any processes that look suspicious to investigate further.

How do you force quit an application on a Mac?

Press these three keys together: Option, Command, and Esc (Escape). This is similar to pressing Control-Alt-Delete on a PC. Or choose Force Quit from the Apple menu  in the corner of your screen.


2 Answers

You should use Launch Services to do this, specifically the function LSFindApplicationForInfo().

You use it like so:

#import <ApplicationServices/ApplicationServices.h>

CFURLRef appURL = NULL;
OSStatus result = LSFindApplicationForInfo (
                                   kLSUnknownCreator,         //creator codes are dead, so we don't care about it
                                   CFSTR("com.apple.Safari"), //you can use the bundle ID here
                                   NULL,                      //or the name of the app here (CFSTR("Safari.app"))
                                   NULL,                      //this is used if you want an FSRef rather than a CFURLRef
                                   &appURL
                                   );
switch(result)
{
    case noErr:
        NSLog(@"the app's URL is: %@",appURL);
        break;
    case kLSApplicationNotFoundErr:
        NSLog(@"app not found");
        break;
    default:
        NSLog(@"an error occurred: %d",result);
        break;          
}

//the CFURLRef returned from the function is retained as per the docs so we must release it
if(appURL)
    CFRelease(appURL);
like image 86
Rob Keniger Avatar answered Nov 07 '22 19:11

Rob Keniger


From the command line this seems to do it:

> mdfind 'kMDItemContentType == "com.apple.application-bundle" && kMDItemFSName = "Google Chrome.app"'
like image 22
Steve McLeod Avatar answered Nov 07 '22 19:11

Steve McLeod