8 Replies Latest reply on Feb 1, 2010 8:54 AM by Michael L Hale


    Michael L Hale Level 5

      I am trying to send a BridgeTalk message from Photoshop to InDesign and it's not working and I don't understand why. The main script works fine in ESTK with InDesign set as the target. But when I add the BridgeTalk it doesn't.


      Anyone have any suggestions?


      Also does case matter with the enumerators? I have seen sample scripts with both.


      var myImages = new Array();
      myImages.push(new File('~/Desktop/Layer Comp 1.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 2.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 3.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 4.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 5.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 6.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 7.psd'));
      myImages.push(new File('~/Desktop/Layer Comp 8.psd'));
      var pdfFile = new File('~/Desktop/myFirstTest.pdf')
      // adapted from Paul Riggott
      // Code for send message and handling response
      // in the sending application (any message-enabled application)
      var res = undefined;
      var bt = new BridgeTalk;
      bt.target = "indesign";
      // the script passed to the target application
      var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+myImages.toSource()+","+300+","+250+","+pdfFile.toSource()+");");//define the work function and call it with arguments
      bt.body = myScript; 
      bt.onResult = function( inBT ) {myReturnValue(inBT.body); }// call the result processing function 
      // send the message and wait up to 10 sec for responce
      // function to process the return string
      function myReturnValue(str){
           //process the results. here just assign strings
           res = str;
           caption = str;
      // wrap your script in a function
      // this function is in whatever DOM the bridgeTalk target is. 
      // don't have comments in the psRemote function
      function psRemote( images, w, h, pdfFile ){
           function addDocument ( w, h ){
                var myDocument = app.documents.add(false);
                myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
                myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
                myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
                myDocument.documentPreferences.pageWidth = w;
                myDocument.documentPreferences.pageHeight = h;
                myDocument.documentPreferences.facingPages = false;
                var myMasterSpread = myDocument.masterSpreads.item(0);
                var myMarginPreferences = myMasterSpread.pages.item(0).marginPreferences;
                myMarginPreferences.left = 0;
                myMarginPreferences.top = 0;
                myMarginPreferences.right = 0;
                myMarginPreferences.bottom = 0;
                myMarginPreferences.columnCount = 1;
                myMarginPreferences.columnGutter = 0;
                myDocument.pages[0].appliedMaster = myMasterSpread;
                return myDocument;
           function addPage( doc ){
                var page = doc.pages.add();
                page.appliedMaster = NothingEnum.NOTHING;
                return page;
           function placeImage( doc, page, bounds, imageFile ){
                r = page.rectangles.add();
                r.geometricBounds = bounds;
                r.strokeWeight = 0;
                r.strokeColor = doc.swatches.item("None")
                r.place ( imageFile, false );
           function mySnippet( doc, pdfFile ){
                var myDocument = doc;
                     app.pdfExportPreferences.pageRange = PageRange.allPages;
                     app.pdfExportPreferences.acrobatCompatibility = AcrobatCompatibility.acrobat6;
                     app.pdfExportPreferences.exportGuidesAndGrids = false;
                     app.pdfExportPreferences.exportLayers = false;
                     app.pdfExportPreferences.exportNonPrintingObjects = false;
                     app.pdfExportPreferences.exportReaderSpreads = false;
                     app.pdfExportPreferences.generateThumbnails = false;
                          app.pdfExportPreferences.ignoreSpreadOverrides = false;
                     app.pdfExportPreferences.includeBookmarks = false;
                     app.pdfExportPreferences.includeHyperlinks = false;
                     app.pdfExportPreferences.includeICCProfiles = true;
                     app.pdfExportPreferences.includeSlugWithPDF = false;
                     app.pdfExportPreferences.includeStructure = false;
                     app.pdfExportPreferences.interactiveElements = false;
                     app.pdfExportPreferences.subsetFontsBelow = 0;
                     app.pdfExportPreferences.colorBitmapCompression = BitmapCompression.zip;
                     app.pdfExportPreferences.colorBitmapQuality = CompressionQuality.eightBit;
                     app.pdfExportPreferences.colorBitmapSampling = Sampling.none;
                     app.pdfExportPreferences.grayscaleBitmapCompression = BitmapCompression.zip;
                     app.pdfExportPreferences.grayscaleBitmapQuality = CompressionQuality.eightBit;
                     app.pdfExportPreferences.grayscaleBitmapSampling = Sampling.none;
                     app.pdfExportPreferences.monochromeBitmapCompression = BitmapCompression.zip;
                     app.pdfExportPreferences.monochromeBitmapSampling = Sampling.none;
                     app.pdfExportPreferences.compressionType = PDFCompressionType.compressNone;
                     app.pdfExportPreferences.compressTextAndLineArt = true;
                     app.pdfExportPreferences.contentToEmbed = PDFContentToEmbed.embedAll;
                     app.pdfExportPreferences.cropImagesToFrames = true;
                     app.pdfExportPreferences.optimizePDF = true;
                     app.pdfExportPreferences.bleedMarks = false;
                     app.pdfExportPreferences.colorBars = false;
                     app.pdfExportPreferences.cropMarks = false;
                     app.pdfExportPreferences.omitBitmaps = false;
                     app.pdfExportPreferences.omitEPS = false;
                     app.pdfExportPreferences.omitPDF = false;
                     app.pdfExportPreferences.pageInformationMarks = false;
                     app.pdfExportPreferences.pdfColorSpace = PDFColorSpace.unchangedColorSpace;
                     app.pdfExportPreferences.registrationMarks = false;
                          app.pdfExportPreferences.simulateOverprint = false;
                     app.pdfExportPreferences.useDocumentBleedWithPDF = false;
                     app.pdfExportPreferences.viewPDF = false;
                myDocument.exportFile( ExportFormat.pdfType, pdfFile, false );
           w = w+'pt';
           h = h+'pt';
           var bounds = ['0pt', '0pt', h, w ];
           var doc = addDocument( w, h );
           placeImage( doc, doc.pages.item(0), bounds, images[0] );
           if( images.length > 1 ){
                for( var i = 1; i < images.length; i++ ){
                     var page = addPage( doc );
                     placeImage( doc, page, bounds, images[i] );
           mySnippet( doc, pdfFile );
           return 'done';
        • 1. Re: InDesign-BridgeTalk-Photoshop
          Peter Kahrel Adobe Community Professional & MVP

          I don't know about your first question. The answer to the second question is yes, it does matter. The enumerationscan be used in two ways: LEFT_EDGES and leftEdges: allcaps and underscores for spaces or initcaps (except first part) with no spaces.



          1 person found this helpful
          • 2. Re: InDesign-BridgeTalk-Photoshop
            Michael L Hale Level 5

            Ok, so that is not the problem. In Photoshop they have to be uppercase.


            I have found one problem. For some reason the BridgeTalk version chokes on




            But is happy with




            So now it will make the doc and paste all the images. But it chokes on the exportPDF function. I guess there is something in that function that works directly in InDesign but not through BridgeTalk.

            • 3. Re: InDesign-BridgeTalk-Photoshop
              Simon Paterson

              I had this problem once and tracked it down to the use of double quotes, believe it or not. I removed them throughout and replaced with singles and had much more success.


              ... Also, just remembered that I had to use the /* */ form of commenting, rather than the // form.

              1 person found this helpful
              • 4. Re: InDesign-BridgeTalk-Photoshop
                Michael L Hale Level 5

                I know that double quotes can cause problems in BridgeTalk but I thought that using toSource fixed that. At least the function below work with Bridge and uses double qoutes.


                function psRemote(fileName){
                     var file = new File(fileName);  
                     var tn= new Thumbnail(file);
                     var md = tn.synchronousMetadata; 
                     var caption = md.read('http://purl.org/dc/elements/1.1/',"description/*[1]");
                     return caption;


                But I didn't know about block comments being ok. I thought no comments where allowed. That's good to know.

                • 5. Re: InDesign-BridgeTalk-Photoshop
                  Kasyan Servetsky Level 5


                  Hi Michel,



                  The problem here is neither in quotes nor in comments.

                  Set a breakpoint at "bt.body = myScript;" line. Run the script, type "myScript" in console and press Enter. Copy the result into a new JS document, remove "myScript Result:" at the top.

                  What do you see?

                  A total mess.

                  But that's the script that you are going to execute in InDesign.



                  At a glimpse, I can see several mistakes:

                  • app.pdfExportPreferences.exportNonPrintingObjects should be pp.pdfExportPreferences.exportNonprintingObjects
                  • if you are sending an object or array via BridgeTalk using toSource(), you should recreate it then using eval().
                  • Bridge talk message is constructed incorrectly.



                  I remade the script and it works for me (CS3 for Windows).

                  However, I don't see why you want to call ID script from PS here.


                  And finally I have suggestion to all: besides a script, please provide also sample files to test the script against them.




                  • 6. Re: InDesign-BridgeTalk-Photoshop
                    Michael L Hale Level 5

                    Thanks, I also got it working by deleting some lines one at a time until it worked. But now that I know that pdfExportPreferences.exportNonprintingObjects was the problem I can add them back. BTW the export options came from the ExportPDFWithOptions.jsx script in indesign_cs4_scripting_guide_scripts from Adobe.


                    To answer your main question, this will be part of a larger Photoshop script. The source files are created by that script. This is to replace the functionally lost when Adobe removed makePDFPresentation from the Photoshop DOM in CS4.


                    How would you construct the BridgeTalk?

                    • 7. Re: InDesign-BridgeTalk-Photoshop
                      Kasyan Servetsky Level 5


                      First, I write a function to be run in the target application (psRemote in your script), test it to make sure it works.

                      Then I construct a BridgeTalk message in the sending application -- define a variable containing the script -- myScript -- which usually consists of 2 lines:


                      1st line either

                      var myScript = psRemote.toString() + '\r';


                      var myScript = psRemote.toSource() + '\r';


                      2nd line calls the function in ID, sending arguments directly from PS

                      myScript += 'psRemote(' + myImages.toSource() + ', ' + 300 + ', ' + 250 + ', ' + pdfFile.toSource() + ');';



                      This is a very handy approach since at any moment you can easily edit the main (psRemote) function.



                      • 8. Re: InDesign-BridgeTalk-Photoshop
                        Michael L Hale Level 5

                        Kasyan, that is what I am doing just in a slightly different way.


                        var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+myImages.toSource()+","+300+","+250+","+pdfFile.toSource()+");");

                        The difference is I use ftn and don't use line breaks.


                        Also because myImages and pdfFile are function arguments they do not need eval.


                        I agree that wrapping the main code in a function is a good way to create the BridgeTalk body.


                        What I don't understand is why InDesign is happy with app.pdfExportPreferences.exportNonPrintingObjects = false; when run in InDesign but not as part of a BridgeTalk message. It seems to me that all that line would do is create a new unused property for app.pdfExportPreferences