Skip to main content
evgeniyaf24436680
Participant
October 11, 2019
Answered

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

  • October 11, 2019
  • 2 replies
  • 1436 views

Hi all,
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.

    This topic has been closed for replies.
    Correct answer evgeniyaf24436680

    I found a solution on another forum and I want to talk about it, maybe this will help someone else.

    I created a path in a JS file:

    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/psd/texture.png";
    csInterface.evalScript('PathToTexture("' + extensionRoot + '")',
    
    function() {
    csInterface.evalScript('step7()');       
    }
    );

    and pass it to the JSX file variable:

    var pathToExtension = '';
    
    function PathToTexture(path) {
        pathToExtension = path;      
    };

    and use this variable in my function in which I need to specify the path:

    desc1.putPath(cTID('null'), new File(pathToExtension));



    2 replies

    evgeniyaf24436680
    evgeniyaf24436680AuthorCorrect answer
    Participant
    October 21, 2019

    I found a solution on another forum and I want to talk about it, maybe this will help someone else.

    I created a path in a JS file:

    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/psd/texture.png";
    csInterface.evalScript('PathToTexture("' + extensionRoot + '")',
    
    function() {
    csInterface.evalScript('step7()');       
    }
    );

    and pass it to the JSX file variable:

    var pathToExtension = '';
    
    function PathToTexture(path) {
        pathToExtension = path;      
    };

    and use this variable in my function in which I need to specify the path:

    desc1.putPath(cTID('null'), new File(pathToExtension));



    Community Expert
    October 15, 2019

    Hi,

    did you find a solution elsewhere?

    You should get the path of the ExtendScript file this way:

     

    var currentPath = File($.fileName).path;

     

    And then could go on from that.

     

    Regards,
    Uwe Laubender

    ( ACP )

     

    evgeniyaf24436680
    Participant
    October 21, 2019

    Thank you for your reply! I found a solution in another forum.