Copy link to clipboard
Copied
The code works very well. The only problem is that there is a hyphen instead of a space. For example,
my-picture-test.jpg.
Is there any way to solve this?
var doc = app.activeDocument;
exportFileToJPEG();
function exportFileToJPEG() {
var newpath = doc.path + "/" + doc.name.substring(0, doc.name.length - 2 + "jpg");
var resolution = 300;
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(newpath);/// + "jpg");
exportOptions.antiAliasing = true;
exportOptions.artBoardClipping = true;
exportOptions.horizontalScale = resolution * 100 / 72;
exportOptions.verticalScale = resolution * 100 / 72;
exportOptions.qualitySetting = 90;
app.activeDocument.exportFile(fileSpec, type, exportOptions);
}
Copy link to clipboard
Copied
Just go ahead and add in the hypens before saving, then rename the saved JPG back to the original name without spaces.
var doc = app.activeDocument;
exportFileToJPEG();
function exportFileToJPEG() {
var newName = doc.name.replace(/\.[a-zA-Z]{2,3}$/, ".jpg");
var newNameWithHyphens = newName.replace(/\s/g, "-");
var fileSpec = new File(doc.path + "/" + newNameWithHyphens);
var resolution = 300;
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
exportOptions.antiAliasing = true;
exportOptions.artBoardClipping = true;
exportOptions.horizontalScale = (resolution * 100) / 72;
exportOptions.verticalScale = (resolution * 100) / 72;
exportOptions.qualitySetting = 90;
app.activeDocument.exportFile(fileSpec, type, exportOptions);
fileSpec.rename(newName);
}
Copy link to clipboard
Copied
Exactly what I was looking for, thank you
Find more inspiration, events, and resources on the new Adobe Community
Explore Now