3 Replies Latest reply on Oct 1, 2009 5:22 PM by Eric @ MCA

    AS/CS2 vs AS/CS4 em space character object reference problem

    Eric @ MCA Level 3

      Hi folks,

       

      In CS2 I have a script that works perfectly to compare characters and figure out if they're special whitespace ones so I can mark them as such.f

       

      Basically, something like:

       

      tell application "Adobe InDesign CS4"
           tell active document
                set storyList to every story
                set selectionSet to null
                if selection exists then
                     set storyList to parent story of selection
                     set selectionSet to selection
                end if
                if selectionSet ≠ null then
                     set charsInStory to selectionSet
                end if
                if class of charsInStory = list then
                     set charsInStory to item 1 of charsInStory
                end if
                
                set specialWhiteSpaceList to {En space, Em space, nonbreaking space, hair space, thin space, punctuation space, figure space, flush space, third space, quarter space, sixth space, tab, end nested style}
                
                repeat with thisChar in (object reference of every character of charsInStory) as list
                     if specialWhiteSpaceList contains (contents of thisChar) then
                          display dialog "Special Whitespace Character found at index " & index of thisChar & "!"
                     end if
                end repeat
                
           end tell
      end tell
      

       

      In CS2, this script will work perfectly. In CS4, it crashes on the first em or en-space it hits saying:

       

      Can't make " " into type string.

       


      Any one have any idea how to compare the current character against a list of whitespace possibilities in CS4? For bonus weirdness, I also noticed that if I select the character via "get character i of story j", contents is set to " ", whereas if I select the character and do "get contents of selection, it returns "Em space".

       

      Argh!

       

      Thanks in advance,

      Eric.

        • 1. Re: AS/CS2 vs AS/CS4 em space character object reference problem
          Eric @ MCA Level 3

          OK, I figured out how to duct tape around it.

           

          This does NOT work:

           

                    repeat with thisChar in (object reference of every character of charsInStory) as list
                         if specialWhiteSpaceList contains (contents of thisChar) then
                              display dialog "Special Whitespace Character found at index " & index of thisChar & "!"
                         end if
                    end repeat

           

          but if I manually address it by character and story indexes, it DOES work:

                    repeat with thisChar in (object reference of every character of charsInStory) as list
                    set thisCharIndex to index of thisChar
                    set thisStoryIndex to index of parent story of thisChar
                    if specialWhiteSpaceList contains (contents of character thisCharIndex of story thisStoryIndex) then
                            display dialog "Special Whitespace Character found at index " & index of thisChar & "!"
                       end if
                    end repeat

           

          If anyone wants to take a whack at explaining what's happening, feel free!

          • 2. Re: AS/CS2 vs AS/CS4 em space character object reference problem
            sstanleyau Level 4

            The problem is that contents has two functions. Your "thisChar" contains a reference, and asking for the contents of it just returns the reference, not the contents of what's referred to. Try rewriting your loop as "repeat with i from 1 to count of..." and you'll see it will work fine.

            1 person found this helpful
            • 3. Re: AS/CS2 vs AS/CS4 em space character object reference problem
              Eric @ MCA Level 3

              Thanks, Shane. I tried using an "i" loop before posting and it didn't seem to work either. Which is when I finally figured out that I could reference by character and story index instead (after posting).

               

              What is still the most weird to me is that the script works in CS2 but fails in CS4.