Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Participant ,
Apr 27, 2011 Apr 27, 2011

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

TOPICS
Scripting
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 28, 2011 Apr 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:

shell("sh "+myFile);

Translate
LEGEND ,
Apr 28, 2011 Apr 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;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 28, 2011 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2011 Apr 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:

shell("sh "+myFile);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 28, 2011 Apr 28, 2011

Message was edited by: Harihara Sudhan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2011 Apr 28, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines