Skip to main content
Adobe-InDesign_CS4
Inspiring
April 28, 2011
Answered

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

  • April 28, 2011
  • 1 reply
  • 3511 views

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

This topic has been closed for replies.
Correct answer John Hawkinson

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:

1 reply

John Hawkinson
Inspiring
April 28, 2011

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;
}

Adobe-InDesign_CS4
Inspiring
April 28, 2011

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

John Hawkinson
John HawkinsonCorrect answer
Inspiring
April 28, 2011

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: