Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guide ,
Mar 02, 2025 Mar 02, 2025

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

 

TOPICS
Bug , Feature request , How to , Import and export , Performance , Scripting
548
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 02, 2025 Mar 02, 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';
    
...
Translate
Community Expert ,
Mar 02, 2025 Mar 02, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 02, 2025 Mar 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2025 Mar 03, 2025

@dublove

 

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2025 Mar 02, 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);
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 03, 2025 Mar 03, 2025

HI Eugene Tyson

Thank you, you are the God of my heart

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2025 Mar 03, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2025 Mar 04, 2025
LATEST

Sorry ~

I forgot it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 02, 2025 Mar 02, 2025

Check out these scripts:

Save with backup

Save versions

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines