5 Replies Latest reply on Mar 17, 2016 8:47 AM by 1CM69

    Open chm Help file from script

    1CM69 Level 1



      My script requires a small help file bundled with it to aid usage.

      I will be compiling my help file in chm format.


      I have added a button on my dialog in order to access this chm file.


      How do I open/display this help file using the button onClick event?



        • 1. Re: Open chm Help file from script
          JJMack Most Valuable Participant

          An onclick button with a function to open the help file. The code in the onclick function may look something like this.


          var scriptFile = String(findScript());                                                                                    // where am I?

          var chmHelp = new File(scriptFile.substr(0, scriptFile.lastIndexOf(".") + 1 ) + "chm"); // change  jsx extension to chm

          if (chmHelp.exists) {

             try{chmHelp.execute(); }

             catch(e){alert('Help "' + chmHelp + " failed to Open.");};


          else {alert('Help file "' + chmHelp + '" was not found.');}                                                   // Help file not with script



          // =================================== Helper functions =================================== //

          function findScript() { // Find the location where this script resides

            var where = "";

            try { FORCEERROR = FORCERRROR;}

            catch(err) { where = File(err.fileName);}

            return where ;


          • 2. Re: Open chm Help file from script
            1CM69 Level 1



            thanks for replying.


            This is what I currently have:


            BTNg.HelpBtn.onClick = function(){
                var STShelp =(new File($.fileName)).parent + '/assets/Help.pdf';
            if (STShelp.exists){
                catch(e){alert('Help ' + STShelp + ' failed to open.');};
            else {alert('Help file ' + STShelp + ' was not found.');}


            The alert is just there to allow me to debug the path to file & it outputs:




            which is perfectly correct, this path is exactly pointing to the location of my Help.pdf file, but & here's the but, it doesn't work, it throws the error 'was not found'


            How can it possible say 'was not found' when is pointing to exactly the correct location?



            • 3. Re: Open chm Help file from script
              1CM69 Level 1

              Also I have tried replacing line3 in above code with:


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


              to make the output easier to read, as:


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


              but it still produces the 'was not found' error

              • 4. Re: Open chm Help file from script
                JJMack Most Valuable Participant

                I install scripts I add to Photoshop in my own Photoshop  Scripts tree and link all versions of Photoshop installed Presets\Scripts folder to my scripts tree.  So there is only one copy of scripts added to Photoshop that needs to be maintained. Photoshop scripts can be installed anywhere they need not be copied into every version of Photoshop installed presets/scripts folders on your system.


                I do not know javascript I just hack at it.  File paths seem to be able to be expressed two ways an internal scripting way and a bazaar way with double \\ to get a single \ because of java syntax rules.


                If you get that message from your code then .exists did not return true.

                your statemet

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

                does not look correct to me then I do not know javascript I think I would have tried something like

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

                STShelp needs to be a file object.

                • 5. Re: Open chm Help file from script
                  1CM69 Level 1



                  thanks for the info & help although it did not function as I required.


                  Here is the working code:


                  BTNg.HelpBtn.onClick = function(){
                  var HelpPath = File($.fileName).parent.fsName + AssetsDir + HelpFile;
                  var STShelp = File(HelpPath);
                  if (STShelp.exists){
                      catch(e){alert('The Help file you requested [' + HelpFile + '] failed to open.\r\r' + e.description,'Unable to open [' + HelpFile + ']');};
                  else {alert('The Help file [' + HelpFile + '] could not be found.\rThis could happen if the file has been moved, renamed or deleted.\rPlease reinstall Star Trail Stacker to resolve this.','Unable to locate [' + HelpFile + ']');}


                  and the variables are:


                  var AssetsDir = '/assets/';
                  var HelpFile = 'Help.pdf';