Skip to main content
mosheyri
Participating Frequently
August 28, 2014
Answered

How to set automatic backups to specific folder in InDesign

  • August 28, 2014
  • 2 replies
  • 12952 views

The following script saves a copy of an InDesign file to a set folder in the same location of its file being backed up.

Question: How can I edit the script to save the backup file to a specific path? For example, to a network drive (Z:/backup). Which line in the script should be changed?

Much is appreciated.

//saveVersions.jsx

//DESCRIPTION: Saves the active document versions in a numbered loop

#targetengine "session"

var myEventListenerVersions = app.addEventListener("beforeSave", SaveVersion);  

  

function SaveVersion()

{

    var myFolderName = 'Backup';

    var myDoc = app.documents.firstItem();

    // Create Backup only if the document has already secured after production

    // (That exists as a file on a disk)

    if (myDoc.saved == true)

    {

        var myCounter = getVersion (myDoc); // Refers version number; this is re-set if required

        var myPathName = myDoc.filePath.fullName + '/' + myFolderName;

        var mySFolder = Folder(myPathName);

        try {

            //  Create backup folder

            mySFolder.create();

        }

        catch(e)

        {

            alert("Problem when creating the folder")

        }

        // Create version copies

        var myName = setVersionName(myDoc.name, myCounter);

        File(myDoc.fullName).copy(myPathName + "/" + myName);

    }

}

function getVersion(aDoc)

{

    if (myMax = aDoc.extractLabel( 'theMax' ))

    {

        // version number

        myVersion = aDoc.extractLabel( 'theVersion' )

    }

    else

    {

        // version number

        do

        {

            // Prompt max. version number

            myMax = prompt ('Maximum Versions:', 5);

            if (myMax == null)

                exit();

        } while (myMax < 1)

        myVersion = '0';

        aDoc.insertLabel( 'theVersion', myVersion);

        aDoc.insertLabel( 'theMax', myMax);

    }

    // Sichern der Versionsdaten

    myNewVersion = setVersion( aDoc, [myMax, myVersion]);

    return myNewVersion;

}

function setVersion( aDoc, aData )

{

    myNum = Number( aData[1] );

    (myNum >= Number( aData[0] )) ? myNum = 1 : myNum++;

    aDoc.insertLabel( 'theVersion', String( myNum ) );

    return String( myNum );

}

function setVersionName(aName, aCounter)

{

        var myIndex = aName.indexOf( '.indd');

        if (myIndex == -1)

        {

            var theNewName = aName + '_' + aCounter;

        }

        else

        {

            var theNewName = aName.substring(0, myIndex) + '_' +  aCounter + aName.substring(myIndex, aName.length);

        }

    return theNewName;

}

This topic has been closed for replies.
Correct answer Chinnadk

Remove this line: var myFolderName = 'Backup';

Replace this line : var myPathName = myDoc.filePath.fullName + '/' + myFolderName;

with : var myPathName = "Z:/backup";

Regards,

Chinna

2 replies

Chinnadk
ChinnadkCorrect answer
Legend
August 30, 2014

Remove this line: var myFolderName = 'Backup';

Replace this line : var myPathName = myDoc.filePath.fullName + '/' + myFolderName;

with : var myPathName = "Z:/backup";

Regards,

Chinna

mosheyri
mosheyriAuthor
Participating Frequently
August 31, 2014

Thanks a lot. That did the trick for the direct path location.

Obi-wan Kenobi
Legend
August 29, 2014

Hi,

I've not tested your script but do you know the script written by Peter Kahrel?: Free script Batch convert/export InDesign documents | Peter Kahrel

Inspiring
March 14, 2023

dead link…

Community Expert
March 14, 2023