macOS; does JUCE provide a way for a plugin to obtain its own bundleIdentifier at runtime?

With my plugin, I need a way to retrieve the filePath of myself at runtime. I DO NOT know it in advance, as the bundles plist will be created, better don’t ask :wink:

In windows it’s easy, calling GetModuleFileName()

On macOS, using dladdr returns the path of the shared lib executable within a bundle. I could traverse the folder hierarchy up until I find a plist and read it, but there has to be a more elegant way for a shared library to obtain its own NSBundle???

Can I get the bundle with [NSBundle bundleForClass:[self class]], assuming I do this within my class? Or are there plugin format type specific JUCE classes Inheriting from nsobject? I assume the class ID is determined by bundleIdentifier.class, it won’t work otherwise, does it?

See File::getSpecialLocation() … i think it was currentApplicationFile.
https://docs.juce.com/master/classFile.html#a3e19cafabb03c5838160263a6e76313d

Perfect! Thanks

A follow up question though:
I my projucer project builds a VST and a VST3, there is only ONE bundle identifier in projucer settings, which gets used for BOTH shared libs. If both plugintypes of my plugin are loaded by a host process, does this still work??

1 Like

Looks like JUCE does it the dladdr way, so seems to be foolproof.