10 Replies Latest reply on Feb 14, 2013 10:54 AM by [Jongware]

    setting myMasterSpread

    bflydesigner Level 1

      Hi, this is the first time I have ever played with scripting and I have been putting the pieces together just fine, except for this one error.

       

      What I am trying to do is write a script that will put two text boxes in the upper right corner of my master spread so it reads "last modified: modification date".  I have tried tons of different commands/word combinations but I keep getting an error in trying to set myMasterSpread.  What I have so far is:

       

      tell application "Adobe InDesign CS5.5"

                set myDocument to document

                set myMasterSpread to masterspread("A-Master") of myDocument

                set myLeftPage to page 1 of myMasterSpread

                set myRightPage to page 2 of myMasterSpread

                tell myRightPage

                          set myRightHeader to make text frame

                          set geometric bounds of myRightFooter to {-19, 963, -15, 1108}

                          set first baseline offset of text frame preferences of myRightHeader to leading

        offset

                          set contents of myRightHeader to "last modified:"

                          set point size of character 1 of parent story of myRightFooter to 10

                          set justification of character 1 of myRightHeader to left align

                end tell

                tell myRightPage

                          set myRightHeader to make text frame

                          set geometric bounds of myRightFooter to {-29, 1010, -15, 1146}

                          set first baseline offset of text frame preferences of myRightHeader to leading

        offset

                          set contents of myRightHeader to modification date

                          set point size of character 1 of parent story of myRightFooter to 10

                          set justification of character 1 of myRightHeader to left align

                end tell

      end tell

       

      Can someone please help me figure this out??

       

      Thanks!

        • 1. Re: setting myMasterSpread
          Jump_Over Level 5

          Hi,

           

          Notice myRightHeader and myRightFooter. There is a little mess with them.

          I mean, one is created another is set.

           

          rgds

          • 2. Re: setting myMasterSpread
            bflydesigner Level 1

            thanks for pointing that out, but that isn't relative to the master spread problem.

             

            and what do you mean by one is created and the other is set?

            • 3. Re: setting myMasterSpread
              Jump_Over Level 5

              bflydesigner wrote:

              ...............

                        tell myRightPage

                                  set myRightHeader to make text frame

                                  set geometric bounds of myRightFooter to {-19, 963, -15, 1108}

              ..............

               

              You created myRightHeader (one) and try to set gBounds to myRightFooter  (another)

              Thats what I mean.

              • 4. Re: setting myMasterSpread
                bflydesigner Level 1

                ok, so now i have:

                 

                tell application "Adobe InDesign CS5.5"

                          set myDocument to document

                          set myMasterSpread to masterspread1 of myDocument

                          set myLeftPage to page 1 of myMasterSpread

                          set myRightPage to page 2 of myMasterSpread

                          tell myRightPage

                                    set myRightHeader to make text frame

                                    set geometric bounds of myRightHeader to {-19, 963, -15, 1108}

                                    set first baseline offset of text frame preferences of myRightHeader to leading

                  offset

                                    set contents of myRightHeader to "last modified:"

                                    set point size of character 1 of parent story of myRightHeader to 10

                                    set justification of character 1 of myRightHeader to left align

                          end tell

                          tell myRightPage

                                    set myRightHeader to make text frame

                                    set geometric bounds of myRightHeader to {-29, 1010, -15, 1146}

                                    set first baseline offset of text frame preferences of myRightHeader to leading

                  offset

                                    set contents of myRightHeader to modification date

                                    set point size of character 1 of parent story of myRightHeader to 10

                                    set justification of character 1 of myRightHeader to left align

                          end tell

                end tell

                 

                and i get the error# -1728  error string: can't get masterspread1 of document...

                • 5. Re: setting myMasterSpread
                  [Jongware] Most Valuable Participant

                  > .. error string: can't get masterspread1 of document...

                   

                  Without knowing anything of AppleScript: wouldn't that need a space before the "1", like your references to "page 1", "character 1" ...?

                  • 6. Re: setting myMasterSpread
                    bflydesigner Level 1

                    Nah, tried that...this is the error i get then:  "Expected end of line, etc. but found number."   Ha, helpful, right??

                     

                    maybe i should try learning how to do this with Java...i don't know java and that would probably be of greater benefit to me and my job

                    • 7. Re: setting myMasterSpread
                      [Jongware] Most Valuable Participant

                      Java would not be very useful (other than that it's a good programming language). InDesign does not support Java right away; I think it's (remotely) possible but you'd need to jump through some hoops to get it to run. Presumably, you meant Javascript! (Which is not related to, derived from, or otherwise equal or comparable to Java, other than that both start with the same four letters and both are programming languages.)

                       

                      I had a quick go at converting your AppleScript to Javascript, but I ran into a couple of problems right away. I converted your commands to similar syntax, so I guess that at least some of your own problems arise for the same reasons.

                       

                      * "set geometric bounds of myRightFooter" -- no myRightFooter yet, presumably you meant 'myRightHeader'

                      * {-19, 963, -15, 1108} is in points? It's a bit low ... only 4 pts high.

                      * "set point size of character 1 .." -- only the first character?

                      * "set justification of character 1 .." -- 'tho this doesn't apply here, since Justification is always per paragraph

                       

                       

                      Anyway, this works for me. I didn't convert the second section, it's just the same code again but with different coordinates.

                       

                       // tell application "Adobe InDesign CS5.5"
                       // ** JS: not necessary if you double-click the script in ID itself
                       #target indesign
                       
                      // set myDocument to document
                      var myDocument = app.activeDocument;
                       
                      
                      // set myMasterSpread to masterspread("A-Master") of myDocument
                       // ** JS uses a function called 'item':
                      var myMasterSpread = myDocument.masterSpreads.item("A-Master");
                       
                      // set myLeftPage to page 1 of myMasterSpread
                       // ** JS starts counting at 0:
                      var myLeftPage = myMasterSpread.pages[0];
                       
                      // set myRightPage to page 2 of myMasterSpread
                      var myRightPage = myMasterSpread.pages[1];
                       
                      // tell myRightPage
                      // actually, "with(x)" is 'considered harmful' by experienced JS programmers
                       // but at this stage you shouldn't really care 
                      with (myRightPage)
                      {
                       
                      //  set myRightHeader to make text frame
                       // ** JS: function is called 'add'
                        var myRightHeader = textFrames.add();
                       
                      
                      //  set geometric bounds of myRightFooter to {-19, 963, -15, 1108}
                       // ** JS: an array is bracketed by [ .. ]
                        myRightHeader.geometricBounds = [-19,963,-15,1108];
                       
                      //  set first baseline offset of text frame preferences of myRightHeader to leading offset
                       // ** JS: enumerations must be written in full, preceded by their class name
                        myRightHeader.textFramePreferences.firstBaselineOffset = FirstBaseline.LEADING_OFFSET;
                       
                      //  set contents of myRightHeader to "last modified:"
                        myRightHeader.contents = "last modified:";
                       
                      //  set point size of character 1 of parent story of myRightFooter to 10
                       // ** JS would be the same, but I assume you want to format the entire *story* text
                      myRightHeader.parentStory.pointSize = 10;
                       
                      //  set justification of character 1 of myRightHeader to left align
                        myRightHeader.parentStory.justification = Justification.LEFT_ALIGN;
                       
                      // end tell
                      }
                      
                      • 8. Re: setting myMasterSpread
                        -hans- Level 4

                        Hi,

                         

                        modification date remains to the finder -> a file / alias can have a modification date.

                        The ID-doc has a property modified, but it just returns a boolean.

                        • 9. Re: setting myMasterSpread
                          bflydesigner Level 1

                          I did mean Javascript, didn't know they were 2 separate things, that's how much interactive i've done :/  embarassing

                           

                          as for setting "point size of character 1"...i didn't know what the 1 was really for, i was just copying and pasting and trying to make it work and playing.  But thank you so much for doing this for me, I really really appreciate it!  This is the first time I've ever used a forum and what a great resource! Haha.

                           

                          I've entered in the code you entered above in AppleScript Editor and it said I couldn't start with /, so I tried removing all your comments and leaving the javascript like so:

                           

                          #target indesign

                           

                          var myDocument = app.activeDocument;

                           

                          var myMasterSpread = myDocument.masterSpreads.item("A-Master");

                           

                          var myLeftPage = myMasterSpread.pages[0];

                           

                          var myRightPage = myMasterSpread.pages[1];

                           

                          with (myRightPage)

                          {

                           

                            var myRightHeader = textFrames.add();

                           

                             myRightHeader.geometricBounds = [-19,963,-15,1108];

                           

                            myRightHeader.textFramePreferences.firstBaselineOffset = FirstBaseline.LEADING_OFFSET;

                           

                            myRightHeader.contents = "last modified:";

                           

                          myRightHeader.parentStory.pointSize = 10;

                           

                            myRightHeader.parentStory.justification = Justification.LEFT_ALIGN;

                           

                          }

                           

                           

                          But now I get syntax error "Expected end of line, etc. but found identifier." and it highlights "myDocument." any ideas?

                           

                          Thanks.

                          • 10. Re: setting myMasterSpread
                            [Jongware] Most Valuable Participant

                            A Javascript needs to be saved as plain text, with a file extension of ".jsx" (sans the quotes). I think you tried doing it with the AS editor :-)

                             

                            You can use the ExtendScript Toolkit Editor to enter, edit, and save Javascripts (it gets installed along with InDesign, but you may have to search where it ended up on your system), as well as any other plain text editor. As long as you remember to save as plain text, you're good.