PDA

View Full Version : Bundles...




floyde
May 31, 2006, 03:35 PM
I seem to have encountered my first Mac programming pitfall...

I'm writing a Webkit plugin for Safari which at some point loads and executes an Applescript file. I added the script file to my project's resource folder in hopes that I would be able to find it later using the NSBundle class. The problem I have, is that when I try to find the plugin's resource path (in order to load the script), such as:


NSString *scriptPath = [[NSBundle mainBundle] resourcePath];

I get Safari.app's resource path, not the plugin's resource path (which is the one I need). I've been able to load the script with an absolute path, but this approach has a few problems. The plugin can be installed in the users Library folder as well as the system's library folder (so I'd have to check both folders). Also, if the installation path for Safari plugins were to change, my plugin wouldn't work anymore... So how can I dynamically obtain the path of my plugin's Resource folder? thanks



robbieduncan
May 31, 2006, 03:44 PM
Try this: [[NSBundle bundleForClass:[self class]] resourcePath] from any class within your plugin.

floyde
May 31, 2006, 04:11 PM
Thanks, it worked! I guess I'll have to add your name to the credits now ;)

robbieduncan
May 31, 2006, 04:14 PM
Thanks, it worked! I guess I'll have to add your name to the credits now ;)

You can have that one for free :D