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.
1 Correct answer
Not with Javascript, but you can run an Applescript snippet with doScript in Javascript.
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.
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
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 )
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
Copy link to clipboard
Copied
Not with Javascript, but you can run an Applescript snippet with doScript in Javascript.
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"')
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();
}
Copy link to clipboard
Copied
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.

