(BTW: "Table:Select:Table" after "$error = '' " was put there in an effort to see if that would fix my problem, but it did not.)
Code: Select all
$doc = Document.active
$text = $doc.text
$tables = $text.tables
ForEach $index, $table in $tables
$columns = $table.columnCount
$rows = $table.rowCount
$table_no = $index+1
Select Table $table_no
#Run AppleScript on each table
$code = 'tell application "System Events"
tell process "Nisus Writer Pro"
click radio button 3 of radio group 1 of drawer 1 of window 1
select text field 1 of scroll area 1 of drawer 1 of window 1
click button 1 of incrementor 3 of scroll area 1 of drawer 1 of window 1
click button 1 of incrementor 3 of scroll area 1 of drawer 1 of window 1
click button 1 of incrementor 3 of scroll area 1 of drawer 1 of window 1
click button 1 of incrementor 3 of scroll area 1 of drawer 1 of window 1
click radio button 2 of radio group 1 of scroll area 1 of drawer 1 of window 1
click button 1 of list 4 of scroll area 1 of drawer 1 of window 1
end tell
end tell'
$error = ""
Table:Select:Table
Run AppleScript $code, $error
#Set the appropriate style for each column
If $columns == 2
Select Table $table_no
Select Table Cell 1, 1
Table:Select:Columns
Format:Paragraph Style:German Vocabulary
Select Table $table_no
Select Table Cell 1, 2
Table:Select:Columns
Format:Paragraph Style:English Gloss
elseif $columns == 4
Select Table $table_no
Select Table Cell 1, 1
Table:Select:Columns
Format:Paragraph Style:German Vocabulary
Select Table $table_no
Select Table Cell 1, 2
Table:Select:Columns
Format:Paragraph Style:English Gloss
Select Table $table_no
Select Table Cell 1, 3
Table:Select:Columns
Format:Paragraph Style:German Vocabulary
Select Table $table_no
Select Table Cell 1, 4
Table:Select:Columns
Format:Paragraph Style:English Gloss
end
End