0 Replies Latest reply on Jul 11, 2012 7:07 AM by purestblue

    [AS] Iterate over selected table cells and chage based on text content of cell

    purestblue

      InDesign CS2

       

      I imported some text into a text frame, used the 'convert text to table' menu item to turn each line into the row of a table, tabs to separate cells. Most of the cells are blank, some contain a little text I want to keep, and some contain just the letter "N". I want to change the cell fill of those with "N", and also delete the "N".

       

      I'm selecting, with the type tool, just the columns I want the changes made in because the document will have many tables and not all will require this change - though those that won't require the change won't have any "N" cells... maybe it would be easier to write a script to run on all tables in the document?

       

      Now I'm quite new to AppleScript. Here's what I've got:

       

      tell application "Adobe InDesign CS2"

          set myCount to 0

          -- Check we've got a document open

          if (count documents) is not equal to 0 then

              set mySelection to selection

              -- check selection is cells of a table

              if (count mySelection) is not equal to 0 then

                  if class of item 1 of mySelection is contained by {cell}

                      set myCells to item 1 of mySelection

                      repeat with myCell in myCells

                          set myT to text of myCell

                          display dialog myT

                      end repeat

                      display dialog "There are " & myCount & " cells"

                  else

                      display dialog "You have not selected any table cells"

                  end if

                  display dialog "There is nothing selected"

              else

                  display dialog "There is no InDesign document open"

              end if

          end if

      end tell

       

      What this does is report an error showing the strings off all cells concatenated thusly:

       

      Can't make {"string","another string","more","","","","N","","","another string","some words","etc"} into type string.

       

      I'd really appreciate some clues how to proceed with this.