this is one of those situations where i feel like i'm missing something obvious, but with as little knowledge as i have there's a lot to be potentially missed. anyway, enough self-deprecation... this script came from a discussion i found ages ago that fit what i needed to do at the time. i don't remember the exact discussion but Larry G.S. rounded it off and posted this:
**********************************************************
Place_JPG_to_AI.jsx
DESCRIPTION
This script 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.
Modified from Adobe supplied scripts and
scripts by Carlos Canto on Illustrator Scripting
by Larry G. Schneider
**********************************************************/
// uncomment to suppress Illustrator warning dialogs
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var destFolder, sourceFolder, files, fileType;
// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder containing M.E.T. JPEG files', '~' );
// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
// Get all files with JPEG extension
files = sourceFolder.getFiles("*.jpg");
if ( files.length > 0 )
{
// Get the destination to save the files
destFolder = Folder.selectDialog( 'Select the folder where you want to save the AI files.', '~' );
for ( i = 0; i < files.length; i++ )
{
var idoc = app.open(File("/G/Design & Publishing/Elements/Master Templates/Re-Engineering Templates/Illustrator/MET Template 106.82x60.ai")); // open template document. Change the file path for different templates
var ilayer = idoc.layers["Image"];
var iplaced = ilayer.placedItems.add(); // add image place holder
iplaced.file = (files); // place file
var PosXY=new Array(2); // ensure position is 0,0
PosXY[0]=0;
PosXY[1]=0;
iplaced.position = PosXY;
iplaced.embed();
ilayer.dimPlacedImages = false; // do not dim images
ilayer.locked = true; // lock layer
ilayer.printable = true;
var docName = (files.name.split('.'))[0]; // take the first part of the placed file name for the new document
var destFile = new File(destFolder + "/" + docName + ".ai"); // make a new file in the dest folder
var options = new IllustratorSaveOptions(); // new save options
options.compatibility = Compatibility.ILLUSTRATOR15; // save as AICS5. May want to update if we go to CC
options.pdfCompatible = true; // needs to be set to view links in InDesign
// Export as AI
idoc.saveAs(destFile, options); // save the file in the dest folder
idoc.close(SaveOptions.DONOTSAVECHANGES); // close the file without saving
}
alert( 'Files are saved as AI in ' + destFolder );
}
else
{
alert( 'No matching files found.' );
}
}
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS
i edited little bits for our purposes but it's basically the same. user selects a folder with jpegs, a dest folder, and the script places the jpegs on my template and saves them with the original filename. however, occasionally the user will need to do this several times into the same dest folder, and won't necessarily know what jpegs they've already done. so they've ended up overwriting files that might already have been worked on (names can't change after the fact for some very boring and irritating reasons). what they'd like, in that case, is for the script to alert them when files with that filename already exist in the dest folder (but run as normal otherwise). i thought just turning DISPLAYALERTS back on might do this (since that's what saveAs does when you go through it manually) but it didn't seem to make any difference. i can't find clues in the reference, but then i'm not entirely sure what i'm looking for. any help or pointers at any level of detail welcome.
... View more