Skip to main content
dublove
Legend
March 3, 2025
Answered

How do I make a copy backup of an Indeisgn file with a script and rename it?

  • March 3, 2025
  • 3 replies
  • 631 views

I know about backing up IDML files, but for large files, I think it would be faster to copy the indd file directly.

I want to copy the current indd file directly to the “Backup” directory in the same level directory and rename it.
Like this:
aa.indd
After the backup:
... \Backup\2025-03-03-aa.indd

 

Some of the code below is for backing up IDML files and it works fine.

I want to add copy indd file to Backup and change the name .
Please advise how to modify it.
Thanks a lot.

var myDate = new Date();
var myYear = myDate.getFullYear();
var myMonth = ("0" + (myDate.getMonth() + 1)).slice(-2); // Add leading zero
var myDay = ("0" + myDate.getDate()).slice(-2); // Add leading zero
var myFormattedDate = myYear + "-" + myMonth + "-" + myDay;
/**
* Creates a folder inside of the active document’s parent folder 
* @ param the active document 
* @ return the folder’s path 
* 
*/
saveIDML();
function saveIDML() {

		//creat Backup folder
		var myPathName = app.activeDocument.filePath.fsName + '/' + 'Backup';
		var mySFolder = Folder(myPathName);
		try {
			//  Create backup folder
			mySFolder.create();	

    var idmlPath =  app.activeDocument.filePath.fsName.replace(/\\/g,'/')+'/'+"backup"+'/'+myFormattedDate+"-"+app.activeDocument.name.replace(/\.indd|\.indt/g,'.idml');

    app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
    }
	catch(e)
	{
		alert("Problem when creating the folder")
	}
}

 

Correct answer Eugene Tyson
var myDate = new Date();
var myYear = myDate.getFullYear();
var myMonth = ("0" + (myDate.getMonth() + 1)).slice(-2); // Add leading zero
var myDay = ("0" + myDate.getDate()).slice(-2); // Add leading zero
var myFormattedDate = myYear + "-" + myMonth + "-" + myDay;

saveBackupFiles();

function saveBackupFiles() {
    var doc = app.activeDocument;
    var docPath = doc.fullName.fsName.replace(/\\/g, '/'); // Get .indd file path
    var backupFolderPath = doc.filePath.fsName + '/' + 'Backup';
    var backupFolder = Folder(backupFolderPath);
    
    try {
        // Create Backup folder if it doesn’t exist
        if (!backupFolder.exists) {
            backupFolder.create();
        }

        // Save IDML file
        var idmlPath = backupFolderPath + '/' + myFormattedDate + "-" + doc.name.replace(/\.indd|\.indt/g, '.idml');
        doc.exportFile(ExportFormat.INDESIGN_MARKUP, new File(idmlPath), false);

        // Save INDD file with new name
        var inddBackupPath = backupFolderPath + '/' + myFormattedDate + "-" + doc.name; // Modified INDD name
        var inddFile = new File(docPath);
        var inddBackupFile = new File(inddBackupPath);
        inddFile.copy(inddBackupFile); // Copy the INDD file

    } catch (e) {
        alert("Problem when creating the backup: " + e.message);
    }
}

3 replies

Kasyan Servetsky
Legend
March 3, 2025

Check out these scripts:

Save with backup

Save versions

Eugene TysonCommunity ExpertCorrect answer
Community Expert
March 3, 2025
var myDate = new Date();
var myYear = myDate.getFullYear();
var myMonth = ("0" + (myDate.getMonth() + 1)).slice(-2); // Add leading zero
var myDay = ("0" + myDate.getDate()).slice(-2); // Add leading zero
var myFormattedDate = myYear + "-" + myMonth + "-" + myDay;

saveBackupFiles();

function saveBackupFiles() {
    var doc = app.activeDocument;
    var docPath = doc.fullName.fsName.replace(/\\/g, '/'); // Get .indd file path
    var backupFolderPath = doc.filePath.fsName + '/' + 'Backup';
    var backupFolder = Folder(backupFolderPath);
    
    try {
        // Create Backup folder if it doesn’t exist
        if (!backupFolder.exists) {
            backupFolder.create();
        }

        // Save IDML file
        var idmlPath = backupFolderPath + '/' + myFormattedDate + "-" + doc.name.replace(/\.indd|\.indt/g, '.idml');
        doc.exportFile(ExportFormat.INDESIGN_MARKUP, new File(idmlPath), false);

        // Save INDD file with new name
        var inddBackupPath = backupFolderPath + '/' + myFormattedDate + "-" + doc.name; // Modified INDD name
        var inddFile = new File(docPath);
        var inddBackupFile = new File(inddBackupPath);
        inddFile.copy(inddBackupFile); // Copy the INDD file

    } catch (e) {
        alert("Problem when creating the backup: " + e.message);
    }
}
dublove
dubloveAuthor
Legend
March 3, 2025

HI Eugene Tyson

Thank you, you are the God of my heart

Community Expert
March 3, 2025

If it works for you can please mark as correct answer, or if you need something else let us know.

Willi Adelberger
Community Expert
Community Expert
March 3, 2025

Why not simply package the file and rename the file? Why do you want a script?

dublove
dubloveAuthor
Legend
March 3, 2025

Oh my God.

Why are you packing? Nothing to do ......
The only time you need to pack is when the client is about to confirm the final draft.
Or if you're working on a different computer, you need to pack.

Robert at ID-Tasker
Legend
March 3, 2025

@dublove

 

When you run Package - you can untick fonts/links copying, PDF creation - select only IDML creation.