Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

How to set automatic backups to specific folder in InDesign

$
0
0

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;

}


Viewing all articles
Browse latest Browse all 15932

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>