Search code examples
excelautomationapplescriptadobe-indesign

Applescript + InDesign Selecting Body Rows In Table


I am currently trying to automate some data formatting. The source data is formatted in Excel. The inDesign template is already formatted. I can right click the table and select body rows then paste the data and it looks beautiful. I am looking to remove this step but am unable to figure out how to get applescript to select the table and body rows of the inDesign template. Neither of the following seem to work.

set selection to body rows of table 1 of active document 
select body rows of table 1 of active document

Any help on this would be great.


Solution

  • Unfortunately the select command only works for a single row, and not all of the rows in a selected table.

    Essentially, you must go row by and decide the row type. Once you've decided the row is a body row, you can select it.

    The syntax for adding a selected row to another selected row is super tricky, especially without an example. See the complete script below.

        tell application "Adobe InDesign CC 2015"
    
        set allBodyRows to every row of every table of every story of active document whose row type is body row
    
        set bodyRow to {}
        repeat with i from 1 to (count allBodyRows)
            set bodyRow to item i of allBodyRows
            if i = 1 then
                select bodyRow
            else
                select bodyRow existing selection add to
            end if
        end repeat
    
        end tell