Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Link Chaser, new multi-relink tool.

$
0
0

Hi guys!

After seeing quite a few requests on the forum for a tool to relink multiple images to a different folder (and because i could also use something like this in my workflow) I whiped this up:

 

 

function main() {    var doc = app.activeDocument;    var myLinks = doc.links.everyItem().getElements();    var linkObj = {};    // create inital object    /* linkObject {                    [path]{missingNr,                           arrayOfMissingLinks}                           } */      for (var i = 0; i < myLinks.length; i++) {        if (myLinks[i].status == LinkStatus.LINK_MISSING) {            var myPath = File(myLinks[i].filePath).path.toString();            if (linkObj[myPath] == undefined) {                linkObj[myPath] = {                    missingNr: 1,                    missingLinks: [myLinks[i]],                    newPath: ''                }              }else{                linkObj[myPath].missingNr++;                linkObj[myPath].missingLinks.push(myLinks[i].getElements()[0]);            }        }    }    //$.writeln(linkObj.toSource());    var myDialog = new Window('dialog', 'Link Chaser:', undefined);    var panel1 = myDialog.add('panel', undefined, 'Double click to select new path');    panel1.align = ['fill', 'fill'];    var myList = panel1.add('listBox', undefined, "", {        columnWidths: [160, 160, 130],        numberOfColumns: 3,        showHeaders: true,        columnTitles: ['Old Path', 'New Path', 'Nr. of missing links']    });    myList.size = [450, 200];    myList.align = ['fill', 'fill'];      for (var missingPath in linkObj) {        with(myList.add('item', missingPath)) {            subItems[0].text = linkObj[missingPath].newPath;            subItems[1].text = linkObj[missingPath].missingNr;        }    }    myList.onDoubleClick = function() {        var myNewPath = (new Folder(app.activeDocument.filePath).selectDlg("Select New Folder") || '').toString();        myList.selection.subItems[0].text = myNewPath;        linkObj[myList.selection.text].newPath = myNewPath;    }    myDialog.add('button', undefined, "Ok", {        name: "ok"    });    myDialog.add('button', undefined, "Cancel", {        name: "cancel"    });    if (myDialog.show() == 1) {        for (var i in linkObj) {            if (linkObj[i].newPath != '') {                var fixedNr = 0;                var links = linkObj[i].missingLinks                for (var j = 0; j < links.length; j++) {                    var newFile = File(linkObj[i].newPath + "/" + links[j].name);                    if (newFile.exists) {                        fixedNr++;                        links[j].relink(newFile);                    }                  }                alert('In folder:\n' + linkObj[i].newPath + '\n' +                    'Fixed ' + fixedNr + ' links out of ' + linkObj[i].missingNr + '\n' +                    'Please check');            }        }    };}
app.doScript('main()', undefined, undefined, UndoModes.entireScript, "Link Chaser"); 

 

 

It's really fresh, and i didn't do much testing on it, so please check it out and if you encounter problems let me know.

 

Enjoy,

Vlad


Viewing all articles
Browse latest Browse all 37788

Latest Images

Trending Articles



Latest Images

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