Highlighted

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! 🙂
Correct answer by Bronkit | Community Beginner

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.

TOPICS
Scripting

Views

1.6K

Likes

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

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! 🙂
Correct answer by Bronkit | Community Beginner

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.

TOPICS
Scripting

Views

1.6K

Likes

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
May 06, 2020 0
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2020 0
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 07, 2020 1
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2020 0
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2020 1
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 07, 2020 0
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2020 1
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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 07, 2020 0