Search code examples
javascriptpdfphotoshopextendscriptphotoshop-script

Open pdf help file in Extendscript (Photoshop Script)


I have created a small script in Photoshop Extendscript & now wish to add the ability to open a pdf help file from within the script.

I have already created the help file in pdf format and it is located inside a folder called 'assets' which is located in the scripts own parent folder.

I have tried fruitlessly to get the pdf file to display, I just keep getting the error message 'was not found'

Here is my code snippet:

    BTNg.HelpBtn.onClick = function(){

 var STShelp =  (new File($.fileName)).parent + '/assets/Help.pdf';

 alert(STShelp);

  if (STShelp.exists){
    try{STShelp.execute();}
    catch(e){alert('Help ' + STShelp + ' failed to open.');};
    }
else {alert('Help file ' + STShelp + ' was not found.');}
}

The first alert is purely there for me to check the path held within the variable STShelp. The path displayed in this alert is:

/c/Program%20Files/Adobe/Adobe%20Photoshop%20CS6%20(64%20Bit)/Presets/Scripts/Star%20Trail%20Stacker/assets/Help.pdf

which is exactly the correct path, as:

C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Presets\Scripts\Star Trail Stacker\assets\Help.pdf

but then this error is thrown:

Help file /c/Program%20Files/Adobe/Adobe%20Photoshop%20CS6%20(64%20Bit)/Presets/Scripts/Star%20Trail%20Stacker/assets/Help.pdf was not found.

I know the path that is held in the STShelp variable looks a little strange with it's forward slashes & the leading forward slash but I have been assured that this is how Extendscript interprets paths.

I have had some kind of action by changing the line:

var STShelp =  (new File($.fileName)).parent + '/assets/Help.pdf';

to

var STShelp =  (new File($.fileName)).parent;

the alert then shows the path as:

/c/Program%20Files/Adobe/Adobe%20Photoshop%20CS6%20(64%20Bit)/Presets/Scripts/Star%20Trail%20Stacker

which is the Parent folder for the script & when I click the OK button on this alert dialog a folder explorer window opens at this Parent location expecting a manual search to the Help.pdf file by opening the contained 'assets' folder.

If I do this, the Help.pdf does indeed display, so there is nothing screwy with the pdf file itself, I just cannot seem to get to it programmatically.

Any help would be appreciated.

Regards..,


Solution

  • You should get your file like this:

    var path = File($.fileName).parent.fsName + '/assets/Help.pdf';
    var pdf = File(path);
    if(pdf.exists){
        pdf.execute();
    }