6 Replies Latest reply on Mar 16, 2017 5:55 AM by try67

    Update folder with pdf files by dialog, but selection should be remembered

    jessevic

      Hello,

       

      Here below you find a script. If you run that script on a single file, you are able to tag a pdf file in the metadata field Author (file>properties).

      Problem now is: I have 1000 pdf files, when I run the script and choose a "watched folder" and I proceed, then the first pdf will be tagged. After tagging the first file, I need to re set my checkmark again! This I would like to tackle. The script should have to save the selection in his memory during the whole script procedure, so that you have to set the checkmark once instead of 1000 times.

      Once the script is done, the variable/memory of Acrobat should also be cleaned, because if I restart the script and I have to make another selection, this checkmark should then be used.

       

      I hope somebody can help this newbie....

       

      Kind regards

       

       

      var dialog2 =

          {

              initialize: function(dialog) {

                  // Set a default value for checkbox field

                  dialog.load({"ckb1": true });

              },

       

              commit: function(dialog) {

                  // When the user presses "Ok", this handler will execute first

                  var results = dialog.store();

                              var tickedItems = []; 

                              if (results["ckb1"]) 

                                  tickedItems.push("Installation manuals"); 

                              if (results["ckb2"]) 

                                  tickedItems.push("Operation manuals"); 

                              if (results["ckb3"]) 

                                  tickedItems.push("Installer reference guide");

                              if (results["ckb4"]) 

                                  tickedItems.push("User reference guide"); 

                              if (results["ckb5"]) 

                                  tickedItems.push("General safety precautions"); 

                              if (results["ckb6"]) 

                                  tickedItems.push("Declaration of Conformity");

                              if (results["ckb7"]) 

                                  tickedItems.push("Option handbooks");

                              this.results = tickedItems.join(";");

              },

       

              // The dialog box description

              description:

              {

                  name: "Check/uncheck the checkboxes to tag your pdf file(s) in the file properties.",

                  elements:

                  [

                      {

                          type: "view",

                          align_children: "align_left",

                          elements:

                          [

                              {

                                  type: "static_text",

                                  name: "Check/uncheck the checkboxes to tag your pdf file(s) in the file properties. Multi selection is also possible.",

                                  bold: true,

                                  font: "dialog",

                                  char_width: 30,

                                  height: 20

                              },

                              {

                                  type: "check_box",

                                  item_id: "ckb1",

                                  name: "Installation manuals"

                              },

                                                      {

                                  type: "check_box",

                                  item_id: "ckb2",

                                  name: "Operation manuals"

                              },

                              {

                                  type: "check_box",

                                  item_id: "ckb3",

                                  name: "Installer reference guide"

                              },

                                                      {

                                  type: "check_box",

                                  item_id: "ckb4",

                                  name: "User reference guide"

                              },

                                                      {

                                  type: "check_box",

                                  item_id: "ckb5",

                                  name: "General safety precautions"

                              },

                                                      {

                                  type: "check_box",

                                  item_id: "ckb6",

                                  name: "Declaration of Conformity"

                              },

                                                      {

                                  type: "check_box",

                                  item_id: "ckb7",

                                  name: "Option handbooks"

                              },

                             

                          ]

                      },

       

                      {

                          type: "gap",    //Add a small vertical gap between

                          height: 10      //check boxes and buttons

                      },

       

                      {

                          type: "ok_cancel",

                          ok_name: "Ok",

                          cancel_name: "Cancel"

                      }

                  ]

              }

          };

      this.info.author=""

      if ("ok"==app.execDialog(dialog2)){

          this.info.title=dialog2.results

      };

        • 1. Re: Update folder with pdf files by dialog, but selection should be remembered
          try67 MVP & Adobe Community Professional

          You can use a global variable to store the values and re-use them between files.

          You will need to use a different script to clear that global value when the batch process is complete, or to restart Acrobat, though.

          • 2. Re: Update folder with pdf files by dialog, but selection should be remembered
            jessevic Level 1

            Yes, sounds indeed good about the saved variable. But where do I have to place the codes (locations?) in my script? I suppose that step 1 must be inserted somewhere at the almost end, but step 2 I do not have any idea.

             

            // Step 1: Will Close Script, Save the setting

            global.test = this.info.title;

             

            // Step 2: Document Level Script, Restore the setting

            this.test = global.this.info.title;

            • 3. Re: Update folder with pdf files by dialog, but selection should be remembered
              try67 MVP & Adobe Community Professional

              No, step 2 needs to be something like this:

               

              if (global.test!=null) {

                // apply the title automatically using the global variable; do not display the dialog window.

              } else {

              // insert here your code with the dialog and then save the result to the global variable

              }

              • 4. Re: Update folder with pdf files by dialog, but selection should be remembered
                jessevic Level 1

                thanks try67, there is still a lot of training required for me...

                • 5. Re: Update folder with pdf files by dialog, but selection should be remembered
                  jessevic Level 1

                  First I was (and still am) quite happy with the script. But, there is still a kind of pitfall: the global variable and especially if I have to close Acrobat and restart if I have to make another selection.

                  try67 suggested previously already to use a different script to clean the global variable.

                  Maybe somebody can brainstorm with me and give me hints: I have 200 files to tag. I run the script, make my selection of files, folders, open files (select the right selection if you start with running the sequence). The tagging starts. When tagging is done (the whole selection, folders, file I have selected), the script stops and should then delete the global variable.

                   

                  First I had in mind: I create an additional button in the dialog box ("clean the cache") to delete the global variable. BUT when I start with tagging and tagging is finished and I rerun the script, the tagging just continues (of course because the global variable is not null!).

                   

                  1

                  Can I foresee when the whole procedure is done, that the pop appears so that I'm able to clear the cache? If yes, please how, remember I'm a dummy.

                   

                  2

                  The button "clear cache" should be linked on a script to clean the cache, something like "delete global.variable" Right? That script should be located almost at the bottom just below the action of the OK button.

                   

                  Here below, you can find my code.

                   

                   

                  if (global.variable!=null) {

                      this.info.title=global.variable

                    // apply the title automatically using the global variable; do not display the dialog window.

                   

                  } else {

                   

                  // insert here your code with the dialog and then save the result to the global variable

                  var dialog2 =

                      {

                          initialize: function(dialog) {

                              // Set a default value for checkbox field

                              dialog.load({"ckb1": true });

                          },

                   

                          commit: function(dialog) {

                              // When the user presses "Ok", this handler will execute first

                              var results = dialog.store();

                                          var tickedItems = []; 

                                          if (results["ckb1"]) 

                                              tickedItems.push("Installation manuals"); 

                                          if (results["ckb2"]) 

                                              tickedItems.push("Operation manuals"); 

                                          if (results["ckb3"]) 

                                              tickedItems.push("Installer reference guide");

                                          if (results["ckb4"]) 

                                              tickedItems.push("User reference guide"); 

                                          if (results["ckb5"]) 

                                              tickedItems.push("General safety precautions"); 

                                          if (results["ckb6"]) 

                                              tickedItems.push("Declaration of Conformity");

                                          if (results["ckb7"]) 

                                              tickedItems.push("Option handbooks");

                                          this.results = tickedItems.join(";");

                          },

                   

                          // The dialog box description

                          description:

                          {

                              name: "Check/uncheck the checkboxes to tag your pdf file(s) in the file properties.",

                              elements:

                              [

                                  {

                                      type: "view",

                                      align_children: "align_left",

                                      elements:

                                      [

                                          {

                                              type: "static_text",

                                              name: "Check/uncheck the checkboxes to tag your pdf file(s) in the file properties. Multi selection is also possible.",

                                              bold: true,

                                              font: "dialog",

                                              char_width: 30,

                                              height: 20

                                          },

                                          {

                                              type: "check_box",

                                              item_id: "ckb1",

                                              name: "Installation manuals"

                                          },

                                                                  {

                                              type: "check_box",

                                              item_id: "ckb2",

                                              name: "Operation manuals"

                                          },

                                          {

                                              type: "check_box",

                                              item_id: "ckb3",

                                              name: "Installer reference guide"

                                          },

                                                                  {

                                              type: "check_box",

                                              item_id: "ckb4",

                                              name: "User reference guide"

                                          },

                                                                  {

                                              type: "check_box",

                                              item_id: "ckb5",

                                              name: "General safety precautions"

                                          },

                                                                  {

                                              type: "check_box",

                                              item_id: "ckb6",

                                              name: "Declaration of Conformity"

                                          },

                                                                  {

                                              type: "check_box",

                                              item_id: "ckb7",

                                              name: "Option handbooks"

                                          },

                                         

                                      ]

                                  },

                   

                                  {

                                      type: "gap",    //Add a small vertical gap between

                                      height: 10      //check boxes and buttons

                                  },

                   

                                  {

                                      type: "ok_cancel_other",

                                      ok_name: "Ok",

                                      cancel_name: "Cancel",

                                                          other_name: "Clear setting in cache"

                                  }

                              ]

                          }

                      };

                   

                  this.info.author=""

                  if ("ok"==app.execDialog(dialog2)){

                      this.info.title=dialog2.results

                  global.variable=dialog2.results

                  };

                  };

                  };

                  • 6. Re: Update folder with pdf files by dialog, but selection should be remembered
                    try67 MVP & Adobe Community Professional

                    The "Clear Cache" button should be separate from the tagging script. You can assign it to a menu item.