Copy link to clipboard
Copied
We are getting InDesign CS6 documents. Most of these documents have .txt files placed as links. Does anyone have a script that will check an open document for txt links and if one or more exists, unlink them. This seems to work, but I don't know what else it is unlinking...
app.activeDocument.links.everyItem().unlink()
I don't really feel safe using this because other images or links I want to keep could be deleted with this. I would like to narrow it down to look for and unlink txt files only.
I'd really appreciate any help! Thanks in advance!
Danny
You could loop through all links, and check their names, something like this:
var link;
var linkName;
var links = app.activeDocument.links;
for (var i=links.length-1; i>=0; i--){
link = links;
linkName = link.name;
if (link.name.substr(linkName.length-4) == '.txt'){
link.unlink();
}
}
Copy link to clipboard
Copied
You could loop through all links, and check their names, something like this:
var link;
var linkName;
var links = app.activeDocument.links;
for (var i=links.length-1; i>=0; i--){
link = links;
linkName = link.name;
if (link.name.substr(linkName.length-4) == '.txt'){
link.unlink();
}
}
Copy link to clipboard
Copied
Hm.
I'd rather check for the parent object of a particular link.
If it's a Story object, it's safe to assume you have a linked text file.
var d=app.documents[0];
var allTheLinks = d.links;
for(var n=allTheLinks.length-1;n>=0;n--){
var link = allTheLinks
; if(link.parent.getElements()[0].constructor.name === "Story"){link.unlink()};
};
The advantage is that you need not to look for every file extension or possible kind of file associated with a text file.
Uwe
Copy link to clipboard
Copied
Both work perfect for what I need. Thanks for your help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now