Skip to main content
dublove
Legend
Mar 3, 2025 2:52 AM UTC
Answered

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

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")
	}
}

 

Eugene TysonCorrect answer
Community Expert
Mar 3, 2025 6:59 AM UTC
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);
    }
}

8 replies

Kasyan Servetsky
Legend
Mar 3, 2025 7:27 AM UTC

Check out these scripts:

Save with backup

Save versions

Translate
Eugene TysonCommunity ExpertCorrect answer
Community Expert
Mar 3, 2025 6:59 AM UTC
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);
    }
}
Translate
dublove
dubloveAuthor
Legend
Mar 3, 2025 8:00 AM UTC

HI Eugene Tyson

Thank you, you are the God of my heart

Translate
Community Expert
Mar 3, 2025 9:05 AM UTC

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

Translate
Willi Adelberger
Community Expert
Community Expert
Mar 3, 2025 4:53 AM UTC

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

Translate
dublove
dubloveAuthor
Legend
Mar 3, 2025 7:59 AM UTC

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.

Translate
Robert at ID-Tasker
Legend
Mar 3, 2025 8:26 PM UTC

@dublove

 

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

 

Translate