Finally able to take a look at your reply. Unfortunately, I can't get it to work. I'm struggling to make sense of it.
The error is gone but it doesn't switch to the doc with -A4 in the name. Should it?
getDocumentByRegex(/(-A4)/g);
function getDocumentByRegex(regex) {
for (var i = 0; i < app.documents.length; i++)
var doc = app.documents[i];
if (regex.test(doc.name))
return doc;
}
Hi @JustyR, the first problem is I left out a pair of braces in my function code earlier—I typed it on my phone away from my computer—so it wasn't working right.
The second issue is that the function only gets the document. You then need to make it the active document. See the whole thing here:
var myA4Doc = getDocumentByRegex(/-A4/g);
if (myA4Doc != undefined)
app.activeDocument = myA4Doc;
function getDocumentByRegex(regex) {
for (var i = 0; i < app.documents.length; i++) {
var doc = app.documents[i];
if (regex.test(doc.name))
return doc;
}
}
So first we get the document (myA4Doc) and then—if it was found—we set the activeDocument to be it.
- Mark