Switching between applications

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

mattski

Switching between applications

Post by mattski »

OK. I looked here and there, got some bridgetalk sample scripts and I'm here:

if I run this from PS it will tell me the size of the jpg, then I want it to open ID create a frame, which it does, and put this size (thumbWidth) in the frame instead of the text. Can anyone help me with this, pretty please?
Code: Select allvar doc = app.activeDocument;
var thumbWidth = doc.width;

alert(thumbWidth);

function SnpSendMessageToInDesign() {
   
   this.requiredContext = "\tExecute against Bridge CS5 main engine,\n InDesign CS5 must also be running.";
   $.level = 1; // Debugging level   
}

SnpSendMessageToInDesign.prototype.run = function() {
   var retval = true;
   if(!this.canRun()) {
      retval = false;   
      return retval;
   }
   // Create the message object
   var bt = new BridgeTalk();
   // Initialize with the target and message string
   bt.target = "indesign-6.0.6";
   bt.body = "var SnpSentMessage = {}; SnpSentMessage.create = " + createInDesignObjects.toString();
   bt.body += "SnpSentMessage.create();"
   bt.onError = function(errObj)
   {
      $.writeln(errObj.body);
   }
   bt.onResult = function(resObj)
   {
      var retval = eval(resObj.body);
      $.writeln("SnpSendMessageToInDesign: (Bridge) received result = " + retval);
      $.writeln("SnpSendMessageToInDesign: (Bridge) the process of creating objects in InDesign has finished...");
      BridgeTalk.bringToFront("indesign-6.0.6");
   }
   bt.send();
   $.writeln("SnpSendMessageToInDesign: (Bridge) BridgeTalk.send() invoked, SnpSendMessageToInDesign.run() exiting");
      
   return retval;
}

SnpSendMessageToInDesign.prototype.canRun = function() {
   // Must run in PS
   // InDesign must be running
   if((BridgeTalk.appName == "photoshop") && BridgeTalk.isRunning("indesign-6.0.6")) {
      return true;
   }
   // Fail if these preconditions are not met.
   $.writeln("ERROR:: Cannot run SnpSendMessageToInDesign");
   $.writeln(this.requiredContext);
   return false;
}

function createInDesignObjects() {
   $.writeln("SnpSendMessageToInDesign: (InDesign) entering createInDesignObjects");
//   var mydoc = app.activeDocument;
   var mydoc = app.documents.add();
   with(mydoc.pages.item(0)) {
         myframe = textFrames.add(mydoc.layers.item("Layer 1"));
         myframe.geometricBounds = ["20mm", "50mm", "40mm", "140mm"];
         myframe.contents = "This is where the variable should go";
   }
   $.writeln("SnpSendMessageToInDesign: (InDesign) leaving createInDesignObjects");
   return true;
}

if(typeof(SnpSendMessageToInDesign_unitTest )  == "undefined") {
   new SnpSendMessageToInDesign().run();
}