ExtendScript – Illustrator: How to Zip Folder

How to zip a folder in illustrator.

This takes the help of an apple script.

//Part 1: Extendscript looks like this
//1. Get terminal command in form of string 
var zipTerminalCommand = terminalCmdToZip();
//2. export terminal command string to a text doc
sendToClipboardDoc(zipTerminalCommand)
//3. Run apple script app to use terminal command
//Change the “YourUserName” part
myAppleScriptPath = “/Users/YourUserName/Desktop/YourAppleScript.app”
runAppleScript(myAppleScriptPath)
//=========================================
// FUNCITONS FOR RUNNING TERMINAL COMMAND
//=========================================
//Just returns the terminal command to zip a folder 
function terminalCmdToZip(){
//Change the “YourUserName” part
    var myFoldersParent = “/Users/YourUserName/Desktop”; //path to the parent folder of the file you want to zip. So maybe you want to zip a folder on the desktop. This path should go to desktop
    var nameOfFolderToBeZipped = “woo!”;  // this is the name of the folder that is being zipped up
varnameOfNewZippedFolder=nameOfFolderToBeZipped+”.zip”; //Just the name of your new zip, not a path. I’ll just assume it’s the same name as your folder.
varterminalCommand=’cd ‘+”‘”+myFoldersParent+”‘”+’ && zip -r -X ‘+”‘”+nameOfNewZippedFolder+”‘”+’ ‘+”‘”+nameOfFolderToBeZipped+”‘”;
returnterminalCommand
}//
//end function
function sendToClipboardDoc(saveThis) {
try{
//var myUserName = $.getenv(‘USER’)
varpathToClipboardDoc=”~/Documents/cbClipboardData.txt”;
varmyDataLog=newFile(pathToClipboardDoc); //This will create a file if one doesn’t already exist
myDataLog.open(“w”);
myDataLog.write(saveThis);
myDataLog.close();
}catch(err){}
}//
//end function
// =====================================
function runAppleScript(pathToScript){
//alert(‘running!’)
myScript=File(pathToScript)
if (myScript.exists) {
myScript.execute();
}//end if
}//
//end function

–Part 2: This is the apple script part. We use it to run terminal commands.
— change the “YourUserName” part

–Get info from text doc for variable

set textDoc to POSIX file “/Users/YourUserName/Documents/cbClipboardData.txt”

set textDocContents to (read textDoc)

–display dialog textDocContents

do shell script textDocContents

 


 

 

Tags:

How to run terminal command with illustrator through extendscript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s