Here is an updated version, using the artboard name rather than hard coding the text in:
// https://forums.adobe.com/thread/2615190
// Save the active .ai file and create a PDF file of artboard 1 and JPG files of artboards 2 & 3
#target illustrator
// Make Illustrator the frontmost application in case we double clicked the file
// app.bringToFront();
// https://forums.adobe.com/message/10703953#10703953
// The active document
var doc = app.activeDocument;
// The path of the original document
var originalDocPath = doc.path;
// The name of the original document
var originalDocName = doc.name;
// Get just the file name, ignore the file extension
// originalDocName = originalDocName.replace(/\.[^\.]+$, ""/)
var originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")
var ab1Name = doc.artboards[0].name;
var ab2Name = doc.artboards[1].name;
var ab3Name = doc.artboards[2].name;
// Setup pdf save options
var opts = new PDFSaveOptions();
opts.preserveEditability = false; // hack to restrict artboard & reduce file size of final PDF
opts.artboardRange = "1";
opts.pDFPreset = "[Illustrator Default]";
// Save the document in the original folder using the original name as a PDF with _ProductionWorksheet
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_" + ab1Name + ".pdf"), opts);
// Now export out JPEG files of artboards 2 & 3
// Possible sources of code:
// https://forums.adobe.com/message/10882995#10882995
// https://forums.adobe.com/message/9462145#9462145
// https://forums.adobe.com/message/10832229#10832229
var resolution = 300;
var artboard2 = 1;
var artboard3 = 2;
var dest1 = originalDocPath + "/" + originalDocName + "_" + ab2Name
var dest2 = originalDocPath + "/" + originalDocName + "_" + ab3Name
exportFileToJPEG1 (dest1, resolution, artboard2);
function exportFileToJPEG1 (dest1, resolution, artboard2) {
var doc = app.activeDocument;
doc.artboards.setActiveArtboardIndex(artboard2);
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest1);
exportOptions.antiAliasing = true;
exportOptions.artBoardClipping = true;
exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size,
exportOptions.verticalScale = resolution*100/72;
exportOptions.qualitySetting = 100;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
exportFileToJPEG2 (dest2, resolution, artboard3);
function exportFileToJPEG2 (dest2, resolution, artboard3) {
var doc = app.activeDocument;
doc.artboards.setActiveArtboardIndex(artboard3);
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest2);
exportOptions.antiAliasing = true;
exportOptions.artBoardClipping = true;
exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size,
exportOptions.verticalScale = resolution*100/72;
exportOptions.qualitySetting = 100;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
// Run the menu command
// app.executeMenuCommand('save');
// Or use the DOM code instead
app.activeDocument.save();
// Optionally close the original doc
app.activeDocument.close();
// Completed Notice
alert("Script Completed!" + "\n" + "Master .ai file saved. Production Worksheet .pdf file and Front/Back View .jpg files created.");