Build PluginDescription in plugin at runtime


consider a macOS vst plugin. It’s a bundle, say “/path/to/plugin.vst”.
the executable location of the plugin bundle is “/path/to/plugin.vst/Contents/MacOS/executable” (specified in the bundles plist.

so, at runtime, within “executable”, I need to create a PluginDescription object for identification of itself, don’t ask why :wink:
For identification, I need at least the fileOrIdentifier and a UID. For VST plugins, fileOrIdentifier needs to be the bundle path, not the executable path!

I’m perfectly able to get the path to the executable of myself within executable (dladdr). But how do I get the CFBundleRef of the bundle containing myself?

String bundlePath = "/path/to/YourBundle.vst";    

if (CFStringRef pathCFString = CFStringCreateWithCString (kCFAllocatorDefault, bundlePath.toRawUTF8(), kCFStringEncodingUTF8))
    if (CFURLRef url = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, pathCFString, kCFURLPOSIXPathStyle, 1))
        if (CFBundleRef bundle = CFBundleCreate (kCFAllocatorDefault, url))
            // Use bundle

            CFRelease (bundle);
        CFRelease (url);
    CFRelease (pathCFString);


Problem is: I don’t have the bundle identifier. I am in the bundle dylib and don’t know anything more!


Can you work out the relative path to the bundle from the executable?