5 Replies Latest reply on Oct 17, 2013 12:28 AM by Kasyan Servetsky

    Modifying an old script from Dave Saunders

    Sandee Cohen Adobe Community Professional

      I've gotten permission from Dave Saunders to ask someone here to help modify a script he wrote way back when.


      The script is posted at:




      The purpose of the script is to change the Crop options of an already placed PDF (includes AI and INDD) file.


      The script was written in 2006 for CS2 and so it doesn't work in today's environment.


      I'm posting a copy of the text in the hope it doesn't get garbled.


      //DESCRIPTION: Allows user to change PDF-import cropping preference

      ©Copyright 2006 PDS Associates

      This script must not be distributed without first obtaining written permission of:

      Dave Saunders, proprietor
      PDS Associates
      P.O. Box 127
      Allenhurst, NJ 07711-0127

      e-mail: davesaunders@pdsassoc.com

      // Destroy any existing dialogs
      if (app.dialogs.length > 0) app.dialogs.everyItem().destroy();
      curSetting = app.pdfPlacePreferences.pdfCrop;
      userChooses = askUser(curSetting);
      app.pdfPlacePreferences.pdfCrop = userChooses

      // +++++++ Functions Start Here +++++++++++++++++++++++

      function interactWithAll() {
      if (app.version == 3) {
      app.userInteractionLevel = UserInteractionLevels.interactWithAll;
      } else {
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

      function askUser(curValue){
      var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];
      var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];
      cv = -1;
      for (var j = cropValues.length – 1; j >= 0; j–) {
      if (curValue == cropValues[j]) {
      cv = j;
      if (cv == -1) errorExit(“Current value of crop preference not recognized”);
      with (app.dialogs.add({name:”Place PDF Crop Preference”})) {
      with (dialogColumns.add()) {
      with (dialogRows.add()) {
      staticTexts.add({staticLabel:”Choose preference:”});
      uchoose = dropdowns.add({stringList:cropChoices, selectedIndex:cv})
      if (!show()) {
      // User canceled;
      } else {
      value = cropValues[uchoose.selectedIndex];
      return value

      function errorExit(message) {
      if (arguments.length > 0) {
      if (app.version != 3) { beep() } // CS2 includes beep() function.
      exit(); // CS exits with a beep; CS2 exits silently.


      If you are interested in this challenge, your modified script will be mentioned at InDesignSecrets.com where we can link to your download page as well as extoll the brilliance of your scripting abilities. Sorry, no money, just glory.


      Send me a message at Sandee at mac dot com if you want to tackle the script.



        • 1. Re: Modifying an old script from Dave Saunders
          Marc Autret Level 5

          Okay I want glory


          Let's try to make it short:


          // PDFImportCropPref Reloaded
          // (should work in ID CS/CS2/CS3/CS4/CS5/CS6/CC)
              for(k in o) o.hasOwnProperty(k) &&
                  (a['_'+z]=t=+o[k]) &&
                  (a[z++]=k.substr(5).replace(r,' ')) &&
                  [k] = +UserInteractionLevels.interactWithAll;
              (t=o.dialogs).length && t.everyItem().destroy();
              r=(t=t.add({name:"Place PDF Crop Preference"}))
                  .staticTexts.add({staticLabel:"Choose preference: "})
              t.show() && (o.pdfPlacePreferences.pdfCrop=a['_'+r.selectedIndex]);




          • 2. Re: Modifying an old script from Dave Saunders
            Jump_Over Level 5



            ... end of competition ...



            • 3. Re: Modifying an old script from Dave Saunders
              Sumit_Garg Adobe Employee

              After CS4 there are changes in "Pdfcrop" enums list.

              Instead of "CROP_CONTENT" new enums were introduced "CROP_CONTENT_ALL_LAYERS" and "CROP_CONTENT_VISIBLE_LAYERS". hence this script does not work in current versions of InDesign.


              if you replace two lines:


                   var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];

                   var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];


              With these lines:


                   var cropChoices = ["Art", "Bleed", "ContentAllLayers","ContentVisibleLayers", "Media", "PDF", "Trim"];

                   var cropValues = [1131573313, 1131573314, 1131561324,1131566703, 1131573325, 1131573328, 1131573332];


              It will be compatible with CS5 and later versions of InDesign.


              Or, You can use @Marc script , that is more generic.

              • 4. Re: Modifying an old script from Dave Saunders
                Dave Saunders Level 4

                Thanks Marc and Sumgarg for helping Sandee. I've been in hospital for three weeks and am only now able to starting thinking again.



                • 5. Re: Modifying an old script from Dave Saunders
                  Kasyan Servetsky Level 5

                  I wish you a quick & speedy recovery, Dave!

                  I’ve learned a lot from your posts, site and blog. Without people like you, I‘d never become a scripter. Thank you a lot!