tags:

views:

42

answers:

1

Hello All,

I am using following code to fetch the path of the application. It works for all cases but fails for front row.

CFStringRef cfStrAppShortName = NULL;
FSRef        appRef;
CFURLRef cfAppUrlRef = NULL;
CFBundleRef cfAppBundleRef = NULL;
CFDictionaryRef cfAppDictRef = NULL;
CFStringRef cfStrAppBundleName = NULL;
OSErr osErr;

cfStrAppShortName = CFSTR(Front Row);

if(cfStrAppShortName != NULL)
{
    osErr = LSFindApplicationForInfo(kLSUnknownCreator,NULL,cfStrAppShortName,&appRef,NULL);
    if(osErr == noErr) 
    {
        cfAppUrlRef = CFURLCreateFromFSRef ( kCFAllocatorDefault, &appRef);
        cfAppBundleRef = CFBundleCreate (kCFAllocatorDefault,cfAppUrlRef);
        cfAppDictRef = CFBundleGetInfoDictionary (cfAppBundleRef);
        cfStrAppBundleName = (CFStringRef)CFDictionaryGetValue (cfAppDictRef,kCFBundleNameKey);
    }

I was expecting application path from Applications folder, but it comes from /system/coreservices/..

This happens for all items present in /system/library/coreservices/.. .

Is there any was that it should not look in /system/library/coreservices.. or any better solution? Can anyone help me?

Thanks in Advance.

Thanks, Rahul

A: 

A more reliable way to identify an application is by bundle identifier. In the case of Front Row, for example, there are two separate applications with the same name:

  • /Applications/Front Row.app: com.apple.frontrowlauncher
  • /System/Library/CoreServices/Front Row.app: com.apple.frontrow

Looking at the bundle identifiers, it looks like this function is returning the path to the correct Front Row after all, since the one in /Applications is just a launcher.

But you shouldn't rely on that—the function could return the launcher's path at any time. Moreover, anybody could create an application bundle and name it “Front Row”.

Use the bundle identifier, so that you are always asking for the correct application.

Peter Hosey
I have only application name with me. Eg Front Row. I dont have bundle identifier.
Rahul
Can you be more specific? How is it that you can have the name but not the bundle identifier of the app you want?
Peter Hosey
Its actually a client server application where server sends the name of application to be launched or closed. So, being on client side I just have the name of application, on which actions are to be performed.
Rahul
Are you writing the server as well? If so, make it send the bundle identifier instead of the name.
Peter Hosey
NO, I am not writing server. Making it send the bundle identifier instead of the name cannot be solution. From user point of view if I am sending name. I Guess, we need to do something like getting the proper bundle identifier from name. Which again bring us to same point. Any other solution?
Rahul
Nope. The name is inherently ambiguous; reducing ambiguity is what the bundle identifier is for. It's currently picking the right Front Row, so you can settle for that for now, but the long-term solutions—as long as switching to bundle identifiers is not an option—consist only of whitelisting and/or blacklisting and/or preferring certain paths (e.g., in this case, preferring /System/Library/CoreServices/Front Row.app over /Applications/Front Row.app).
Peter Hosey