Skip to content

Instantly share code, notes, and snippets.

@chancrescolex
Created September 4, 2015 20:27
Show Gist options
  • Save chancrescolex/339505a8c14293b1e466 to your computer and use it in GitHub Desktop.
Save chancrescolex/339505a8c14293b1e466 to your computer and use it in GitHub Desktop.
Adobe Illustrator script to convert files to AI
/**********************************************************
ADOBE SYSTEMS INCORPORATED
Copyright 2005-2010 Adobe Systems Incorporated
All Rights Reserved
NOTICE: Adobe permits you to use, modify, and
distribute this file in accordance with the terms
of the Adobe license agreement accompanying it.
If you have received this file from a source
other than Adobe, then your use, modification,
or distribution of it requires the prior
written permission of Adobe.
*********************************************************/
/**********************************************************
Save as AI.jsx
DESCRIPTION
This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as AIs in the user desired destination with the same
file name.
Based on Adobe's "Save as PDFs" sample script, intended for Illustrator CS6
**********************************************************/
// Main Code [Execution of script begins here]
// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, IllustratorSaveOptions;
// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to AI', '~' );
// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
{
// Get the destination to save the files
destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted AI files.', '~' );
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files[i]); // returns the document object
// Call function getNewName to get the name and file to save the AI
targetFile = getNewName();
// Save as AI
sourceDoc.saveAs(targetFile, IllustratorSaveOptions );
sourceDoc.close();
}
alert( 'Files are saved as AI in ' + destFolder );
}
else
{
alert( 'No matching files found' );
}
}
/*********************************************************
getNewName: Function to get the new file name. The primary
name is the same as the source file.
**********************************************************/
function getNewName()
{
var ext, docName, newName, saveInFile, docName;
docName = sourceDoc.name;
ext = '.ai'; // new extension for AI file
newName = "";
for ( var i = 0 ; docName[i] != "." ; i++ )
{
newName += docName[i];
}
newName += ext; // full AI name of the file
// Create a file object to save the AI
saveInFile = new File( destFolder + '/' + newName );
return saveInFile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment