I have found @Arthur's script very useful. However, I wanted to use it only only afterSave
, but also afterSaveAs
(which was easy to extend: just append another event listener command) and afterSaveACopy
(which I could not accomplish by myself; I have seeked the help at community.adobe.com).
Now I have a working script that works for all three use cases, see below.
// src: https://community.adobe.com/t5/indesign/get-the-name-of-the-document-created-by-save-a-copy/m-p/10997427#M179868 (based on https://graphicdesign.stackexchange.com/a/71770, which is based on https://graphicdesign.stackexchange.com/a/71736)
// author: Fabian Morón Zirfas ([email protected]), modified by Arthur ([email protected]), modified by Sunil_Yadav1 ([email protected])
// date: 24 March 2020
// Set a targetengine to make this work
#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);