11 Replies Latest reply on Sep 10, 2010 9:01 AM by Stephen Horne

    find change object applescript

    Stephen Horne Level 1

      I'm trying to set the find change options using applescript to search for only graphics frames with a certain fill colour, then apply a stroke to them. But I can't get it to work. I've done the same thing with find change text, but I can't figure out how to do it with objects. Here's what I've tried:

       

      set colorList to {"YGB Red", "RF Orange", "Black", "YGB Green"}

      tell application "Adobe InDesign CS3"

           repeat with i from 1 to (count colorList)

                set find object preferences to nothing

                set change object preferences to nothing

       

                set fill color of find object preferences to (item i of colorList) --I've tried (item i of colorList as string) with the same error

                set stroke weight of change object preferences to 0.6

                set stroke color of change object preferences to "Paper"

                change object

           end repeat

      end tell

       

      the error message is thus: Adobe InDesign CS3 got an error: Invalid value for set property 'fill color'. Expected swatch, string or nothing, but received "YGB Red".

       

      "YGB Red" is definitely the name of a swatch in the document, and is capitalised correctly.

       

      Anyone have any ideas?

       

      Thanks.

        • 1. Re: find change object applescript
          sstanleyau Level 4

          It looks like it's insisting on a swatch, so you'll probably have to fool it by making one at the application level, and deleting it when you're finished.Something like this:

           

          set colorList to {"YGB Red", "RF Orange", "Black", "YGB Green"}

          tell application "Adobe InDesign CS3"

          repeat with i from 1 to (count colorList)

          try

          set tempColor to color (item i of colorList)

          set colorExists to true

          on error

          set tempColor to make color with properties {name: (item i of colorList)}

          set colorExists to false

          end try

          set find object preferences to nothing

          set change object preferences to nothing

           

          set fill color of find object preferences to tempColor

          if not colorExists then delete tempColor

          set stroke weight of change object preferences to 0.6

          set stroke color of change object preferences to "Paper"

          change object

          end repeat

          end tell

          --

          Shane Stanley <sstanley@myriad-com.com.au>

          1 person found this helpful
          • 2. Re: find change object applescript
            Stephen Horne Level 1

            Thanks Shane. I've given that a go, and it runs, but it's not finding anything. When I open the find dialog in indesign it still has the search terms in there from the applescript search, and for both the find fill and the replace stroke colors it shows color: (Unnamed color).

             

            I've just had a bit more of a play with it and it seems to be rather glitchy. When I run your script it gets the color id of each of my swatch names, so for black it returns "color id 5", but when I set the find fill color in indesign to "Black" then tell applescript to get find fill color, it returns "color id 13". So if I put "color id 13" into the script it works. So I can do this for each I guess, but presumably these color ids will vary from document to document (maybe not black).

             

            The next hurdle is to be able to set the stroke alignment of the change object preferences.

             

            When I type:

             

            set stroke alignment of change object preferences to outside alignment

             

            I get:

             

            error "Adobe InDesign CS3 got an error: Object doesn't support this graphic attribute." number 11281

            But when I ask:

            get stroke alignment of change object preferences

             

            it happily returns:

             

            --> outside alignment (default is center, that's my problem).

             

            Any ideas on that one, or do you reckon it's a bug?

             

            Thanks

            • 3. Re: find change object applescript
              sstanleyau Level 4

              You need to specify a target for change object, as in:

               

              change object document 1

               

              The (Unnamed color) thing is correct because you've deleted it by that stage.

               

              The stroke alignment thing looks like a bug, and a nasty one at that. On CS4, it returns nothing all the time -- as do most of the other change object preferences properties, regardless of settings.

              1 person found this helpful
              • 4. Re: find change object applescript
                Stephen Horne Level 1

                Thanks Shane. I still can't get the thing to work, but it's irrelevant anyway if I can't specify outside alignment so I'm going to give up on it. Thanks again.

                 

                Stephen

                • 6. Re: find change object applescript
                  Stephen Horne Level 1

                  Good point. I'll do that.

                  --

                   

                  Stephen Horne

                  • 7. Re: find change object applescript
                    Osinho2

                    Hi Stephen,

                     

                    I read your post and was wondering if you could post the script for "find / change text" you were talking about.

                     

                    I am asking because I have a fairly large catalog file which I created using the data merge function. Unfortunately I have quite a few empty text frames and I would like to have a script that can look for empty text frames and then deletes them...

                     

                    Your script sounds like it could help me put it together.

                     

                    Thank you!!

                    • 8. Re: find change object applescript
                      Stephen Horne Level 1

                      I'm afraid I don't have that script anymore, but the following script will delete all empty text frames in all open documents:

                       

                      tell application "Adobe InDesign CS5"

                           repeat with oneDoc in (get documents) -- will repeat with all open documents

                                tell oneDoc

                                     activate

                                     tell spreads

                                          delete (text frames whose contents is "") -- empty text frames

                                     end tell

                                end tell

                           end repeat

                      end tell

                       

                      Hope it helps

                      • 9. Re: find change object applescript
                        Osinho2 Level 1

                        Hi Stephen,

                         

                        thank  you so much for responding...

                         

                        I just came in and will def try it as soon as I get settled in.

                         

                        I will let you know!

                         

                        Thanks!!

                         

                        Marc

                        • 10. Re: find change object applescript
                          Osinho2 Level 1

                          thank you so much!

                           

                          Works like a charm!

                          • 11. Re: find change object applescript
                            Stephen Horne Level 1

                            You're very welcome.

                            --

                            Stephen Horne