Skip navigation
purestblue
Currently Being Moderated

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

Jul 11, 2012 7:07 AM

Tags: #indesign #fill #tables #cs2 #applescript #automation #cells #replace_text

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.

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points