Use Command Line From Illustrator Script?

Community Beginner ,
May 06, 2020

Copy link to clipboard

Copied

Hello,

I'm trying to use Terminal (command line) from Illustrator with ExtendScirpt.

 

I know it's possible in After Effects:

system.callSystem(yourCommand)
 
And in Photoshop:
app.system(yourCommand)
 
Does anyone know if there's a way to run Terminal from Illustrator?
Thank you! 🙂
TOPICS
Scripting

Views

1.9K

Likes

Translate

Translate

Report

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

1 Correct Answer

Community Beginner , May 07, 2020
Bronkit Community Beginner , May 07, 2020
Just sharing my workaround (for Mac). This specific example shows how to zip folders. With the help of AppleScript, I'm running terminal commands in Illustrator like this: //Part 1: Extendscript part looks like this //1. Get terminal command in form of string var zipTerminalCommand = terminalCmdToZip(); //2. export terminal command string to a text doc saveTextDoc(zipTerminalCommand) //3. Run apple script app to use terminal command //Change "YourUserName" part myAppleScriptPath = "/Users/You...

Likes

Translate

Translate
Jump to answer Jump to answer
Participant ,
May 06, 2020

Copy link to clipboard

Copied

I'm just curious what kind of common options that this might provide, if it is doable..

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Bronkit AUTHOR
Community Beginner ,
May 07, 2020

Copy link to clipboard

Copied

My goal currently is to zip a folder. But also just handy in general to use command line 🙂

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
May 06, 2020

Copy link to clipboard

Copied

no, we have no such luxury. As an alternative you could write your terminal commands on a BAT (on Windows) file from jsx. There might be similar alternatives for mac.

 

or another way is to send the system calls to photoshop and have photoshop execute them.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
May 06, 2020

Copy link to clipboard

Copied

You can use osascript command with AppleScript
Here is a typcal usage

//test.scpt

tell application "Adobe Illustrator"
activate
do javascript "alert(app.name)"
end tell


and command

osascript -l JavaScript test.scpt

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Bronkit AUTHOR
Community Beginner ,
May 07, 2020

Copy link to clipboard

Copied

Thank you! 🙂 I ended up using an option like this.

I'll post my solution in this thread for other people looking for solutions.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
May 06, 2020

Copy link to clipboard

Copied

You could use the File objects execute method to execute commands by creating a bat/vbs file in Windows and a .command file on MAC.

 

-Manan

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
May 07, 2020

Copy link to clipboard

Copied

Just sharing my workaround (for Mac). This specific example shows how to zip folders.

 

With the help of AppleScript, I'm running terminal commands in Illustrator like this:

 

//Part 1: Extendscript part looks like this

//1. Get terminal command in form of string
var zipTerminalCommand = terminalCmdToZip();

//2. export terminal command string to a text doc
saveTextDoc(zipTerminalCommand)

//3. Run apple script app to use terminal command
//Change "YourUserName" part
myAppleScriptPath = "/Users/YourUserName/Desktop/YourAppleScript.app"
runAppleScript(myAppleScriptPath)

//=========================================
// FUNCITONS
//=========================================

//Returns the terminal command to zip a folder
function terminalCmdToZip(){

//Change "YourUserName" part
    var myFoldersParent = "/Users/YourUserName/Desktop"; //path to the parent folder of the file you want to zip.
    var nameOfFolderToBeZipped = "woo!";  //name of the folder being zipped
    var nameOfNewZippedFolder = nameOfFolderToBeZipped + ".zip"; //Name of new zip, not a path.
    var terminalCommand = 'cd ' + "'" + myFoldersParent + "'" + ' && zip -r -X ' + "'" + nameOfNewZippedFolder + "'" + ' ' + "'" + nameOfFolderToBeZipped + "'";

    return terminalCommand
}

//exports a text doc with your terminal command
function saveTextDoc(saveThis) {
    try{
        var pathToClipboardDoc = "~/Documents/terminalCmd.txt";
        var myDataLog = new File(pathToClipboardDoc);
        myDataLog.open("w");
        myDataLog.write(saveThis);
        myDataLog.close();

    }catch(err){}
}

//Runs AppleScript
function runAppleScript(pathToScript){
    myScript = File(pathToScript)
    if (myScript.exists) {
        myScript.execute();
    }
}

 

 

 

This is the AppleScript app you'll have to make for this to work

 

--Get info from text doc for variable
--Change the "YourUserName" part
set textDoc to POSIX file "/Users/YourUserName/Documents/terminalCmd.txt"
set textDocContents to (read textDoc)
--display dialog textDocContents

do shell script textDocContents

 

 

Feel free to share if you have a Windows workaround too.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
iconify LATEST
Explorer ,
Oct 20, 2020

Copy link to clipboard

Copied

Adobe extensions allow you to use NodeJS in panels. With access to NodeJS you can easily run command line commands. Do so is pretty easy. The challenge will be creating the CEP (Common Extension Protocol) panel. It's not really that hard and is, for the most part, the same as scripting but with a UI. There is a bit of a learning curve but it isn't terrible if you have some coding experience. CEP panels are built in HTML, CSS, and JS so anyone with basic web development experience cna learn it.

 

Likes

Translate

Translate

Report

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