Skip to main content
Inspiring
February 11, 2011
Question

Finding the path of your filter plugin programmatically?

  • February 11, 2011
  • 2 replies
  • 1797 views

Hi, I've been trying some time to get the path of my plugin so I can reference some resource files in a reliable manner (so no matter where my plugin is within the plugin directory it will work).  I've been trying to use the SP Suites to do this, but I can't seem to get them to work.

My short term goal is to print the path to my plugin binary to console.

My most recent attempt goes like this(from within doContinue):

    SPBasicSuite *sSPBasic = f->sSPBasic; //f being the global filter record passed in by photoshop

    SPAccessSuite *sSPAccess;

    SPErr error = sSPBasic->AcquireSuite(kSPAccessSuite,

      kSPAccessSuiteVersion, (const void**)&sSPAccess);

    if (error) {

        fprintf(stderr, "coudln't acquire access suite\n");

    } else {

        fprintf(stderr, "acquired access suite\n");

    }

    SPPluginRef thisPlugin = NULL;

    error = sSPAccess->GetCurrentPlugin(&thisPlugin);

    if (error) {

        fprintf(stderr, "coudln't get current plugin\n");

    } else {

        fprintf(stderr, "got current plugin\n");

    }

    SPPluginsSuite *sSPPlugins;

    error = sSPBasic->AcquireSuite(kSPPluginsSuite,

      kSPPluginsSuiteVersion, (const void**)&sSPPlugins);

    if (error) {

        fprintf(stderr, "coudln't acquire plugins suite\n");

    } else {

        fprintf(stderr, "acquired plugins suite\n");

    }

    SPPlatformFileSpecification *fileSpec;

    error = sSPPlugins->GetPluginFileSpecification(thisPlugin, fileSpec);

    if (error) {
        fprintf(stderr, "coudln't get file spec\n");
    } else {
        fprintf(stderr, "got file spec\n");
    }

    //fprintf(stderr, "%s\n", fileSpec->nothingherecompiles);

Which results in the following output from gdb:

acquired access suite
got current plugin
acquired plugins suite

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000008

Based on that it seems that GetPluginFileSpecification crashes the program.  However, I'm fairly certain that 'thisPlugin' is not actually valid either, which makes me question whether any of the suites are valid as well.  Is there some sort of initialization I'm missing?  Any help is much appreciated.

This topic has been closed for replies.

2 replies

Inspiring
February 15, 2011

Unportably but perhaps more concisely - for OS X only - you might be able to use some NSBundle methods on your plugin bundle, like resourcePath.

Chris Cox
Legend
February 11, 2011

Or that you failed to provide storage for the spec and just passed in a pointer to something that was supposed to get filled in....

Inspiring
February 11, 2011

I see... I was confused because there's a typo in the documentation that says it 'Files' it in and since we're dealing with files here my brain got confused.

Is it the same case with the SPPluginRef thisPlugin?  How do I determine how much space those pointers need?

Inspiring
February 11, 2011

UPDATE: Here's the solution I've landed on:

   SPBasicSuite *sSPBasic = filterRecord->sSPBasic;

    SPAccessSuite *sSPAccess;
    sSPBasic->AcquireSuite(kSPAccessSuite,
      kSPAccessSuiteVersion, (const void**)&sSPAccess);

    SPPluginRef thisPlugin = (SPPluginRef)filterRecord->plugInRef;

    SPPluginsSuite *sSPPlugins;

    sSPBasic->AcquireSuite(kSPPluginsSuite,
      kSPPluginsSuiteVersion, (const void**)&sSPPlugins);

    SPPlatformFileSpecification fileSpec;

    sSPPlugins->GetPluginFileSpecification(thisPlugin, &fileSpec);

    PSGetPathSuite1 *sPSGetPath;
    sSPBasic->AcquireSuite(kPSGetPathSuite,
      kPSGetPathSuiteVersion1, (const void**)&sPSGetPath);

    char *path = (char*)malloc(256);
    sPSGetPath->GetPathName(&fileSpec, path, 256);

path now contains string of the form "Macintosh HD:Applications:Photoshop:etc"  and I just did some simple string manipulations to get it into the form I want.