4 Replies Latest reply on Apr 18, 2012 10:36 PM by Harbs.

    RE: How to get script to activate?

    Matthew.Fry

      I found a script that saves copies of InDesign pages to the desktop. It works great for my needs.

       

      I would love to have this script activate whenever someone hits the Save shortcut (Command S), which currently saves our InDesign pages to our content management system (WoodWing).

       

      Since I can't have a keyboard shortcut perform two commands at once, I am looking for a scripting solution.

       

      Can anyone point me in the right direction?

       

       

      • • • • • • •

       

      //Save to Backup Folder.jsx

      //

      // This script is designed to save copies of the current document to a backup-location

      //

      var desktop_path = Folder.desktop.toString();

      var backup_path = desktop_path+"/backup"

      if (Folder(backup_path.exists == false )) {

                Folder(backup_path).create();

      }

      if (app.documents.length > 0) {

                main();

      }

       

       

      function main() {

                var doc = app.activeDocument;

                try {

                          if (doc.saved == true) {

                                    var doc_file = doc.fullName;

                                    var doc_name = doc.name;

                                    var now = new Date();

                                    var datestamp = now.getFullYear().toString() + "-" + two_digit(now.getMonth()+1) + "-" + two_digit(now.getDate());

                                    var timestamp =  two_digit(now.getHours()) + two_digit(now.getMinutes()) + two_digit(now.getSeconds());

                                    var target_folder = Folder(backup_path + "/" + datestamp);

                                    if (target_folder.exists == false ) {target_folder.create(); }

                                    var target_file = target_folder.toString() + "/" + timestamp + " — " + doc_name;

                                    if (doc_file.copy(target_file) == false) {

                                              alert("Backup error\rCould not create backup copy.");

                                    }

                          }

                } catch (e) {

                          alert(e);

                }

                doc.save();

       

                function two_digit(n) {

                          if (n < 10) {

                                    return "0" + n.toString();

                          } else {

                                    return n.toString();

                          }

                }

      }