I recently ran across this same issue and couldn't determine a way to set the name correctly before saving/exporting so I instead just rename the files after the save/export. The code below will export the artboard(s) you specify in the `artboardsToExport` array (0-index), then rename the exported file(s) to just "Artboad X.ai". The `baseName` variable is just so I know how to exactly recreate the path for renaming.
doc = app.activeDocument;
exportFiles("TEST");
function exportFiles(baseName) {
var expOptions = new IllustratorSaveOptions();
expOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
expOptions.saveMultipleArtboards = true;
var artboardsToExport = [1, 2];
var ab, tempFile, finalFile, testFile;
for (var i = 0; i < artboardsToExport.length; i++) {
ab = doc.artboards[artboardsToExport[i]];
// When exporting specific artboards, the api only allows specifying the first part of
// the file name, then it appends `_Artboard Name` and add the extension which result in:
//`{baseName}_Artboard X.{extension}`
tempFile = new File(doc.path + "/" + baseName);
// To be able to correctly name the exported file(s), I am recreating the known
// naming convention with a new `file` object to that path
finalFile = new File(doc.path + "/" + baseName + "_" + ab.name + ".ai");
// Since the export exported file path and the preferred file path are different the built-in
// file overwrite protection will not prompt you so and the `rename` method would not
// overwrite the existing file. So, here I do the checking and prompt if needed.
testFile = new File(doc.path + "/" + ab.name + ".ai");
if (testFile.exists) {
if (
!Window.confirm(
"File already exists!\nOverwrite " + ab.name + ".ai?",
"noAsDflt",
"File Already Exists"
)
) {
// If you choose not to overwrite I just remove the exported artboard
finalFile.remove();
continue;
} else {
// Otherwise, I remove the file at that path so the rename works
testFile.remove();
}
}
// Export the file
expOptions.artboardRange = artboardsToExport[i] + 1 + "";
doc.saveAs(tempFile, expOptions);
// Rename the file
finalFile.rename(ab.name + ".ai");
}
doc.close(SaveOptions.DONOTSAVECHANGES);
}