4 Replies Latest reply on Jun 23, 2008 1:07 PM by (xbytor)

    making inDesign wait for Photoshop to finish working

      I'm writing a script that opens the selected images in Photoshop, resizes them, then relinks to the resized files. The problem I'm having is getting the javascript started in inDesign to pause while Photoshop resizes each link. What happens is Photoshop starts working, but the script keeps running in inDesign, so if it tries to relink before Photoshop's done working and the file's been saved, it fails. So I have the script checking for the existence of the file, so it stays in a loop until the file exists. But this seems kludgy. Is there a way to make the script simply pause until Photoshop is finished working?

      Here's a snippet showing how I'm handling it in a kludgy way:

      ScaleInPhotoshop(filePathOfImage, newFilePath);
      // We need this script to pause until Photoshop is done working.
      // So first, look to see if the new file exists. If not, keep waiting and looking.
      while (File(newFilePath).exists == false) {
      // Do nothing, just keep looping.
      }
      //Now relink to the new file:
      selection.itemLink.relink(newFilePath);
        • 2. Re: making inDesign wait for Photoshop to finish working
          Level 1
          Sorry, CS2. I'm in Windows XP.
          • 3. Re: making inDesign wait for Photoshop to finish working
            Level 1
            One trick that's supposed to work in CS3 is to set the timeout value of your BridgeTalk message to Photoshop. If set, it is supposed to make the BridgeTalk call synchronous. I have never tried it. But, I would try doing that here to see if it had any effect, even though you are in CS2. The reason I would try it is that the other options are very limited in CS2.

            You've hit on one of the options, the second: in your Photoshop script, send a new BridgeTalk message back to InDesign to continue the processing. Note that the script that was running in ID will have quit by then, so you will have to figure out all of the needed information to continue from that point.

            Regards

            Bob
            • 4. Re: making inDesign wait for Photoshop to finish working
              Level 1
              Bob Stucky wrote:
              > You've hit on one of the options, the second: in your Photoshop script, send a new BridgeTalk message back to InDesign to continue the processing. Note that the script that was running in ID will have quit by then, so you will have to figure out all of the needed information to continue from that point.

              I wrote this up for PSCS2. Call sendSync (instead of send) with a timeout value
              in seconds. It returns the result of the call. CS3 add a timeout parameter to
              'send' that functions similarly.

              BridgeTalk.prototype.sendSync = function(timeout) {
              // XBridgeTalk.log("BridgeTalk.sendSync(" + timeout + ")");

              var self = this;

              self.onResult = function(res) {
              this.result = res.body;
              this.complete = true;
              }
              self.complete = false;

              self.send();

              if (timeout) {
              for (var i = 0; i < timeout; i++) {
              BridgeTalk.pump(); // process any outstanding messages
              if (!self.complete) {
              $.sleep(1000);
              } else {
              break;
              }
              }
              }

              var res = self.result;
              self.result = self.complete = self.onResult = undefined;

              // XBridgeTalk.log("BridgeTalk.sendSync => " + res);

              return res;
              };

              -X
              --
              for photoshop scripting solutions of all sorts
              contact: xbytor@gmail.com