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

Is it possible to run a mac os shell command within javascript in Indesign like in photoshop

New Here ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Hey Community, is it possible to run a shell command within javascript in Indesign
like in photoshop for example "app.system('say "hello world"')" is there a Indesign equivalent ?
Thanks for help.

Views

914

Translate

Translate

Report

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

People's Champ , Apr 14, 2021 Apr 14, 2021

Not with Javascript, but you can run an Applescript snippet with doScript in Javascript.

Votes

Translate

Translate
Community Expert ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

I've moved this from the Using the Community forum (which is the forum for issues using the forums) to the InDesign forum so that proper help can be offered.

Votes

Translate

Translate

Report

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
Advisor ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Hello,

 

Here's an example of what @TᴀW is taking about that I use to zip the Document Fonts folder.....hope this helps!

var doc = app.documents[0];

myDocFolder = doc.filePath;
var myDocumentFonts = Folder(myDocFolder.fsName + "/Document fonts/");  
if (!myDocumentFonts.exists) {
exit();
}  

CreateFontsZip();
function CreateFontsZip(){
var myFontsZipFolder = myDocumentFonts;
var myFontsZipDestination = doc.filePath;
 var myDocumentFontsZipName = "Document fonts";
   app.scriptArgs.setValue("zip", myFontsZipFolder)
    app.scriptArgs.setValue("zipName", myDocumentFontsZipName)
     app.scriptArgs.setValue("zipLocation", myFontsZipDestination)
     var myFontsZipScript = ''' tell script args
   set myZip to get value name "zip"
 set theZipName to get value name "zipName"
set destFold to get value name "zipLocation"
do shell script ("ditto -c -k --sequesterRsrc " & quoted form of POSIX path of myZip & " " & quoted form of POSIX path of destFold & "" & quoted form of POSIX path of theZipName & "" & ".zip")
end tell '''
app.doScript(myFontsZipScript, ScriptLanguage.applescriptLanguage);
}

Regards,

Mike

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Hi Thomas,

app.system() is not available with ExtendScript for InDesign.

Would file.execute() work for your purpose?

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
New Here ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Hi Uwe,

thanks for your fast response but the "file.execute()" don´t fits my purpose.

I m looking for an "easy" way to use some shell commands in combination with Indesign and Javascript.

I try to avoid to execute a file.

Regards,

Thomas

 

 

Votes

Translate

Translate

Report

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
People's Champ ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Not with Javascript, but you can run an Applescript snippet with doScript in Javascript.

Votes

Translate

Translate

Report

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
New Here ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Thanks TaW and the Community to point me in the right direction.

 

To execute a shell command with javascript in photoshop you can use this code:

app.system('say "hello world"')

 

To execute a shell command with javascript in indesign you can use this code:
Pitfall: if you are using double quotes (") in your shell command you have to use
"quoted form of" like in this example.
myScript = ' do shell script "say " & quoted form of "hello world" '
app.doScript(myScript, ScriptLanguage.applescriptLanguage);
 
best regards
-Thomas

Votes

Translate

Translate

Report

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
New Here ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

I am attaching how I do this in windows, it may also apply to mac as well writing to .sh text file. I basically create a .cmd file that gets executed. If it exits already, I delete it. In this example I am creating a mapped network drive.

 

 

    var cmdFolder = new Folder('~/Desktop/logs/');
        cmdFolder.create();
    var cmdFile = new File(cmdFolder + '/mapDrive.cmd');
        if(cmdFile.exists){
            cmdFile.remove();
        }
        if ( cmdFile.open( "e" )){
            cmdFile.seek( 0, 2 );
            cmdFile.writeln( 'net use Z: \\\\1.1.1.1\\ \/user:sampleUser SamplePassword' );
            cmdFile.close();
            cmdFile.execute();
        }

 

Votes

Translate

Translate

Report

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
New Here ,
Mar 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

LATEST

In Windows it's possible. But I was not able to run a script file (`.sh` or `.command`) which was created on-the-fly via jsx in MacOS. The permission of created file is not enough to run, so user should do `chmod` in Terminal, which is not acceptable. I'm looking for another ways but hopeless so far.

Votes

Translate

Translate

Report

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