• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AppleScript to check all pages within one Indesign (CS6) document have same size.

Guest
Mar 07, 2013 Mar 07, 2013

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!

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 07, 2013 Mar 07, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 07, 2013 Mar 07, 2013

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;}

            };

res.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 11, 2013 Mar 11, 2013

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?

Screen Shot 2013-03-11 at 4.57.57 PM.png

Thanks,

Hasi

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 12, 2013 Mar 12, 2013

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2013 Mar 18, 2013

Copy link to clipboard

Copied

Puzzled - surely this is Java not Applescript as requested??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 18, 2013 Mar 18, 2013

Copy link to clipboard

Copied

It's a javascript (Extendscript) and will run on both mac and pc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2013 Mar 18, 2013

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines