Hi again
This could work for the IDML export
main();
exit();
function main() {
myDoc = app.activeDocument;
f = new File("/Users/afile.idml"); // here you have to adapt it for your needs.
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP,f, false);
}