Helpful File static function on OSX

I add this code to my juce repository every time I pull. Maybe you could add it into the repository if you find it useful. It gets the file for a given bundle identifier.

Note this is only relevant to mac osx so I put it right next to the addToDock Function as this is mac osx only as well.

I am not sure what to do if the file does not exist as OSX is returning that path for the bundle’s file however this works when the bundle id exists, maybe an argument could be added for the workspace to look in as well.

static File GetFileFromBundleID( const String& BundleID) ;

File File::GetFileFromBundleID( const String& BundleID){
    JUCE_AUTORELEASEPOOL
    {
        const char * bundleID = BundleID.toRawUTF8();
        NSString *path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
        
        const char *pathString = [path UTF8String];
        
        File f( pathString );
        
        if (f.exists())
        {
            return f;
        }
        // Not sure what to do here. return f even though it dosn't exist?
        return f;
    }
    
}
1 Like