Bundles...

Discussion in 'Mac Programming' started by floyde, May 31, 2006.

  1. macrumors 6502a

    floyde

    Joined:
    Apr 7, 2005
    Location:
    Monterrey, México
    #1
    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:

    Code:
    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
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Try this: [[NSBundle bundleForClass:[self class]] resourcePath] from any class within your plugin.
     
  3. thread starter macrumors 6502a

    floyde

    Joined:
    Apr 7, 2005
    Location:
    Monterrey, México
    #3
    Thanks, it worked! I guess I'll have to add your name to the credits now ;)
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    You can have that one for free :D
     

Share This Page