Skip to content

Instantly share code, notes, and snippets.

@a1phanumeric
Created March 19, 2013 10:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a1phanumeric/5195080 to your computer and use it in GitHub Desktop.
Save a1phanumeric/5195080 to your computer and use it in GitHub Desktop.
ESTK .jsx script to open directory of .ai files and save them as SVGs with standardised artboards (an artboard which perfectly fits the image).
#target illustrator
var sourceDir,
destDir,
files,
sourceDoc;
sourceDir = Folder.selectDialog( 'Select the import directory.', '~' );
destDir = Folder.selectDialog( 'Select the export directory.', sourceDir.sourceDir );
files = sourceDir.getFiles("*.ai");
if(files.length == 0){
alert("No files to import");
}else{
for(i=0; i < files.length; i++){
sourceDoc = app.open(files[i]);
// Create new filename
var ext = '.svg';
var newName = "";
var dot = files[i].name.lastIndexOf('.');
newName += files[i].name.substring(0, dot);
newName += ext;
targetFile = new File( destDir + '/' + newName );
// Resize artboard
app.activeDocument.artboards[0].artboardRect = app.activeDocument.visibleBounds;
redraw();
// Export as SVG
var opt = new ExportOptionsSVG();
sourceDoc.exportFile(targetFile, ExportType.SVG, opt);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
sourceDoc = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment