Hello tukusejssirs,
Try the script below, it's working for all three scenarios..........
"afterSave"
"afterSaveAs"
"afterSaveACopy"
// Set a targetengine to make this work as Startup script
#targetengine "session"
function saveIDML() {
if(app.layoutWindows.length == 0) {
return;
} else {
var doc = app.activeDocument;
if (!doc.saved) {
alert('Sorry, there was a problem and the document was not saved.');
exit();
}
var inddName = doc.name;
var idmlName = inddName.replace(".indd", ".idml");
var theFile = File(File(doc.filePath).fsName + "/" + idmlName);
doc.exportFile(ExportFormat.INDESIGN_MARKUP, theFile, false);
}
}
function getFileName(e) {
if(app.layoutWindows.length == 0) {
return;
} else {
var doc = app.activeDocument;
if (!doc.saved) {
alert('Sorry, there was a problem and the document was not saved.');
exit();
}
var newFileName = File(e.properties.fullName).fsName.toString().replace(/\\/g,'/').replace(".indd", ".idml");
doc.exportFile(ExportFormat.INDESIGN_MARKUP, newFileName, false);
}
}
// Listen for the save event
app.addEventListener('afterSave', saveIDML, false);
app.addEventListener('afterSaveAs', getFileName, false);
app.addEventListener('afterSaveACopy', getFileName, false);
Regards,
Mike
Hi mike,
In "afterSaveACopy" event you only need to export IDML as named of copied file then why are you putting all other codes for active document?
Instead you can only have your code like this:
#targetengine "session"
/////////////////////////////////////////////////////////////////////////////////////////////////////
function saveIDML() {
if(app.layoutWindows.length == 0) return;
else if (!app.activeDocument.saved) {
alert('Sorry, there was a problem and the document was not saved.');
return;
}
var idmlPath = app.activeDocument.filePath.fsName.replace(/\\/g,'/')+'/'+app.activeDocument.name.replace(/\.indd|\.indt/g,'.idml');
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
function saveACopyIDML(e) {
var idmlPath = File(e.properties.fullName).fsName.toString().replace(/\\/g,'/').replace(/\.indd|\.indt/g,'.idml');
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Listen for the save event
app.addEventListener('afterSave', saveIDML, false);
app.addEventListener('afterSaveAs', saveIDML, false);
app.addEventListener('afterSaveACopy', saveACopyIDML, false);
/////////////////////////////////////////////////////////////////////////////////////////////////////
P.S : Always try not to put a lot of extra code which is not needed for better understanding for users.
Best
Sunil