Copy link to clipboard
Copied
I have bunch of InDesign (CS6) documents containing different page sizes (some are designed for a particular device and some are designed for multiple devices using alternate layouts). I need to assure all page sizes are same before I run a particular script.
So I need a Applescript which can request a folder location of closed files and then open and run through the InDesigns in that folder (ignoring any other files) and then open a text file report saying all page sizes are same or not. (Sorry! for my English)
Any help is much appreciated!
Copy link to clipboard
Copied
Hi,
var selFolder = Folder.selectDialog();
var inddFiles = selFolder.getFiles('*.indd');
l = inddFiles.length;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
while(l--)
{
currDoc = app.open(inddFiles
, false); allPagesBounds = currDoc.pages.everyItem().bounds;
currDocPagesWidthHeight = new Array();
for(var b = 0; b < allPagesBounds.length; b++)
{
h = allPagesBounds[2];
w = allPagesBounds[3] - allPagesBounds[1];
resString = '' + currDoc.pages.name + ': ' + w + ' x ' + h + '\n';
currDocPagesWidthHeight.push(resString)
}
toFile(currDoc.name.replace(/indd/,''), currDocPagesWidthHeight.join(''));
currDoc.close(SaveOptions.NO);
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
function toFile(targetName, pwh)
{
targetFile = File(selFolder + '/' + targetName + 'txt')
targetFile.open('w');
targetFile.write(pwh);
targetFile.close()
}
quick'n dirty this should list all pagesizes of indd-docs of a chosen folder in the chosen folder with matching inddDocName.
Docs will open faceless ... Javascript.
Hope it'll be of some help
Hans-Gerd Claßen
Copy link to clipboard
Copied
good morning,
changed it a bit. this'll only write a reportfile if there are pages with different pagesizes.
#target Indesign
var selFolder = Folder.selectDialog();
var inddFiles = selFolder.getFiles('*.indd');
l = inddFiles.length;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
while(l--)
{
currDoc = app.open(inddFiles
, false); allPagesBounds = currDoc.pages.everyItem().bounds;
currDocPagesWidthHeight = new Array();
for(var b = 0; b < allPagesBounds.length; b++)
{
h = allPagesBounds[2];
w = allPagesBounds[3] - allPagesBounds[1];
resString = '' + currDoc.pages.name + ': ' + w + ' x ' + h + '\n';
currDocPagesWidthHeight.push(resString)
}
var samePageSizesOrNot = checkUnique(currDocPagesWidthHeight);
switch(samePageSizesOrNot)
{
case false :
toFile(currDoc.name.replace(/indd/,''), currDocPagesWidthHeight.join(''));
currDoc.close(SaveOptions.NO);
break;
default : currDoc.close(SaveOptions.NO);
break;
}
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
function toFile(targetName, pwh)
{
targetFile = File(selFolder + '/' + targetName + 'txt')
targetFile.open('w');
targetFile.write(pwh);
targetFile.close()
}
function checkUnique(someArray) {
var obj = {} ;
var tmpArray = [] ;
for (var i = 0; i < someArray.length; i++) {
var currItem = someArray;
if (! obj[currItem]) {
obj[currItem] = true ;
tmpArray.push(currItem);
} ;
};
if (tmpArray.length === 1)
{
return true;
}else{
return false;}
};
Copy link to clipboard
Copied
Thank you soooo much Hans!
This is really great! Could it be possible to run on a bunch of folders and subfolders and in the end create a single txt file report?
Thanks,
Hasi
Copy link to clipboard
Copied
sure,
still no error-handling included, so use on own risk 😉 ...
#target Indesign
var selFolder = Folder.selectDialog();
if(!selFolder) {exit();};
var allFiles = selFolder.getFiles('*.*');
var currDate = getDate();
var currLogFile = File(selFolder.toString() + '/' + currDate + 'pagesSizeLogFile.txt');
doStuff(allFiles);
currLogFile.execute();
function doStuff(filesFoldersArray){
var l = filesFoldersArray.length;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
while(l--)
{
var currItem = filesFoldersArray
; if(currItem instanceof(Folder)){
nextItems = currItem.getFiles('*.*');
doStuff(nextItems);
}
else if ( currItem.displayName.indexOf('indd') != -1){
currDoc = app.open(currItem, false);
allPagesBounds = currDoc.pages.everyItem().bounds;
currDocPagesWidthHeight = [currDoc.fullName.toString() + ':\n'];
for(var b = 0; b < allPagesBounds.length; b++) {
h = allPagesBounds[2];
w = allPagesBounds[3] - allPagesBounds[1];
resString = '' + currDoc.pages.name + ': ' + w + ' x ' + h + '\n';
currDocPagesWidthHeight.push(resString)
}
var samePageSizesOrNot = checkUnique(currDocPagesWidthHeight);
switch(samePageSizesOrNot)
{
case false :
toFile(currDocPagesWidthHeight.join(''));
currDoc.close(SaveOptions.NO);
break;
default : currDoc.close(SaveOptions.NO); break; }
}
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
}
function toFile(pwh)
{
currLogFile.open('a');
currLogFile.write(pwh);
currLogFile.close()
}
function checkUnique(someArray) {
var tmpArray = [] ;
var tmpString = '';
for (var i = 1; i < someArray.length; i++) {
currItem = someArray;
if (tmpString.indexOf(currItem.slice(2,-1)) === -1){
tmpString = tmpString + ' ' + currItem;
tmpArray.push(currItem);
} ;
};
if (tmpArray.length === 1)
{
return true;
}else{
return false;}
};
function getDate(){
var d = new Date();
var day = d.getDate();
if(day < 10){day = '0' + day;};
var month = d.getMonth() +1;
if(month < 10){month = '0' + month;};
var year = '' + d.getFullYear();
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds();
var dateString = month + day + year.substring(2) + '_' + hours + minutes + seconds + '_';
return dateString;
}
Copy link to clipboard
Copied
Puzzled - surely this is Java not Applescript as requested??
Copy link to clipboard
Copied
It's a javascript (Extendscript) and will run on both mac and pc
Copy link to clipboard
Copied
Thought so. Just OP asked for AS and seemed happy with JS! I think I need to learn JS... I am too stuck in my ways!