5 Replies Latest reply on Apr 28, 2011 5:57 PM by John Hawkinson

    [CS4:JS] How to run ".sh" file through Javascript

    Adobe-InDesign CS4 Level 1

      Dear All,

       

      How to run the ".sh" file through Adobe InDesign Javascript, I used the below coding:

       

      //================== Code =============================//

       

      var myFile = File("xxx/xxx/xxx/Test.sh");

      var Exec = "sh" + " "+ "\""+myFile+"\"";

       

      File(Exec).execute();

       

      //================== End =========================//

       

      the above coding is not working, I checked before without "sh" also, It is not working.

       

      Please anyone can give me the solutions & suggestion, and I will appreciate.

       

       

      Thanks & Regards

      T.R.Harihara SudhaN.,

        • 1. Re: [CS4:JS] How to run ".sh" file through Javascript
          John Hawkinson Level 5

          You can't do it. Your only choice is to use VB or AppleScript, as appropriate for your platform, to call the shell.

          This is what I use under OS X:

           

          function shell(cmd) {
              var
                  rv,
                  call ='do shell script "'+
                      cmd.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+
                      '"';
          
              try {
                  rv = app.doScript(call,
                      ScriptLanguage.APPLESCRIPT_LANGUAGE);
              } catch(e0) {
                  rv = e0+"\n"+(rv?"":rv);
              }
              return rv;
          }
          
          • 2. Re: [CS4:JS] How to run ".sh" file through Javascript
            Adobe-InDesign CS4 Level 1

            Dear Hawkinson,

             

              Many thanks for this quick reply, I'm really very happy, but unfortunately the script is return the "Permission denied" value.

            I used the below code, Please kindly change if anything is wrong.

             

            //====================== Script Source =====================//

            var myFile ="/Applications/MacXinPro/IDMLExportparse.sh";

            shell(myFile);

             

            function shell(cmd) {
            var
            rv,

            call ='do shell script "'+ cmd.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"';

            try {

            rv = app.doScript(call,ScriptLanguage.APPLESCRIPT_LANGUAGE);

            } catch(e0) {

            rv = e0+"\n"+(rv?"":rv);

            }

            return rv;

            }

             

            //====================== End : Script Source =====================//

             

            //=========== Output ================//

            Execution finished. Result: Error: sh: /Applications/MacXinPro/IDMLExportparse.sh: Permission denied
            undefined.

             

            Please kindly help me...

             

             

            Thanks & Regards

            T.R.Harihara SudhaN

            • 3. Re: [CS4:JS] How to run ".sh" file through Javascript
              John Hawkinson Level 5

              Does your file IDMLExportparse.sh have execute permissions set?

              If you open Terminal.app and type

               

                   /Applications/MacXinPro/IDMLExportparse.sh

               

              does it work? Or do you need to run "sh"? If so, either adjust the

              permissions with

               

                   chmod a+x /Applications/MacXinPro/IDMLExportparse.sh

               

              or change the JavaScript to:

               

              shell("sh "+myFile);

               

              • 4. Re: [CS4:JS] How to run ".sh" file through Javascript
                Adobe-InDesign CS4 Level 1

                 

                Message was edited by: Harihara Sudhan

                • 5. Re: [CS4:JS] How to run ".sh" file through Javascript
                  John Hawkinson Level 5

                  Hmm...looking back at my script I notice now:

                  } catch(e0) {
                          rv = e0+"\n"+(rv?"":rv);
                  

                  I'm not quite sure what I was thinking here. I think the ?: is backwards and this was intended to be (rv?rv:"") but that doesn't really make sense either, since that's the same as (rv), and rv never gets set if there's an exception anyhow. so it could have just been:  rv = e0;

                   

                  Oh well... It doesn't break anything, just looks ugly.