Search code examples
javascriptadobeextendscript

How to change absolute path to relative in .jsx file. (Photoshop extension script)?


I have a problem while developing an extension for Photoshop. I have generated action code that I write in a .jsx file. I need to change the absolute path to a relative one so that the user has access to the file, regardless of where the extension was installed.

.jsx file:

function step7(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putInteger(cTID('Idnt'), 4);
    desc1.putPath(cTID('null'), new File("~/AppData/Roaming/Adobe/CEP/extensions/Mockups_Extension/psd/texture.png"));
    desc1.putEnumerated(cTID('FTcs'), cTID('QCSt'), sTID("QCSAverage"));
    var desc2 = new ActionDescriptor();
    desc2.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), -1.13686837721616e-13);
    desc2.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 0);
    desc1.putObject(cTID('Ofst'), cTID('Ofst'), desc2);
    desc1.putUnitDouble(cTID('Wdth'), cTID('#Prc'), 249.5);
    desc1.putUnitDouble(cTID('Hght'), cTID('#Prc'), 249.5);
    executeAction(cTID('Plc '), desc1, dialogMode);
  };

Any help is most appreciated.


Solution

  • You need to pass your extension path from CEP-side.

    CEP:

    //when initialization happens
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION);
    csInterface.evalScript('updateGlobalVars("' + extensionRoot + '")', function() {
        csInterface.evalScript('step7()');
    });
    

    JSX:

    var pathToExtension = '';
    
    function updateGlobalVars(path) {
        pathToExtension = path;
    };
    
    function step7(arg1, arg2) {
        alert(pathToExtension)
    };