Skip to main content
Participant
September 4, 2023
Question

Photoshop c++ plugin code to open file that is located at "filepath".

  • September 4, 2023
  • 2 replies
  • 220 views

Hello,
I want to open a file in photoshop through the plugin code so i can automate few files and perform some operations on it .

This topic has been closed for replies.

2 replies

Participant
September 4, 2023

This is the code i had refered from automation documentation , since its older code some of the it is deprecated .
can someone provide a alternative for it.

/* Open file that is located at "filepath" */
SPErr OpenFile(char* filepath) {
    SPErr error = kSPNoError;
    Handle tempAlias;
    PIActionDescriptor result = NULL;
    PIActionDescriptor desc = NULL;

#if Macintosh
    NewAliasMinimalFromFullPath(
        strlen(filepath),
        filepath,
        nil,
        nil,
        &(AliasHandle)tempAlias
    );
#else
    size_t size = strlen(filepath);
    tempAlias = sPSHandle->New(size + 1);
    if (tempAlias != NULL) {
        GlobalLock(tempAlias);
        strncpy(*tempAlias, filepath, strlen(filepath) + 1);
        GlobalUnlock(tempAlias);
    }
#endif

    error = sPSActionDescriptor->Make(&desc);
    if (error) goto returnError;

    error = sPSActionDescriptor->PutAlias(desc, keyNull, tempAlias);
    if (error) goto returnError;

    error = sPSActionControl->Play(&result, eventOpen, desc, plugInDialogSilent);
    if (error) goto returnError;

returnError:
#if Macintosh
    if (tempAlias != NULL) DisposeHandle(tempAlias);
#else
    if (tempAlias != NULL) sPSHandle->Dispose(tempAlias);
#endif

    /* Free descriptors and references */
    if (desc != NULL) error = sPSActionDescriptor->Free(desc);
    if (result != NULL) error = sPSActionDescriptor->Free(result);

    return error;
} /* end OpenFile */

 

Stephen Marsh
Community Expert
Community Expert
September 4, 2023

We don't have much activity around SDK. Alternatives include legacy scripting or the new UXP method.

 

https://developer.adobe.com/photoshop/

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-2021-sdk-guide-where-is-it/td-p/11915431