Importing or placing styled text in an inDesign story

Way way back in the day (Mac OS9) I was able to do this with both Quark and inDesign, but I can’t figure out how to do it with inDesign now, and all the scripting samples I can find are javascript (which I’m not good at) and don’t really cover this.

In short I have a cell in a table that gets text. Once the text is in place there are as many as four separate style changes in the text.

What I’m doing now is placing the text, then making they style changes. I works but it’s slow. (A typical table has around 1000 cells).

What I’m hoping to do is something like this:

set myTaggedText to "<titleTag>ProgramTitle </titleTag><descTag>Program Description. </descTag> <ratingTag> Program rating </ratingTag> <captionTag> program caption /<captionTag> <timeTag>programTime</timeTag>"

set contents of myTablesCell to myTaggedText

Or, if I must, save the tagged text to disc and import it from the file.

Any suggestions?

→ Script Debugger 8.0.3 (8A49)
→ MacOS 11.6.2
–>Adobe InDesign 2022 17.01

Use nested styles. This is the sort of thing they’re designed for.

I use an external tagged text file and place it in the text frame.

1 Like

Hi. When I do this, I have all of the paragraph, character, etc, styles defined in the document, and then generate a tagged text file (out of an FMP database) that creates and styles the table itself, and creates and styles the cell contents, all upon import of the tagged text file.

I would love to see a sample of both of those!

Nested styles could work, but the text has no delimiter characters and don’t have a set number of characters.

Can you use regular expressions? Or just have your script insert (non-printing) delimiter characters?

I think I could use non printing characters, but I don’t know anything about them.

I could use GREP but I don’t see how that would help.

There’s actually an end nested style character you can insert.

You can define GREP Styles as part of paragraph styles. It lets you define a GREP pattern, and have a character style applied to any matches. You can define multiple GREP Styles.

I don’t know how it works with tables, but for normal text you can select the content of the text box (with formatted text in it) and export this as ‘Adobe InDesign-Tagged-Text’.
In the export dialog you can select between normal or shorten tags and the encoding.

Open the exported file with an Editor and see the tagged text.

Between the nested styles and the GREP styles I’ve made real progress. But I don’t see how to insert the end nested style character from a script. Copying and pasting doesn’t work. Same for Em spaces.

Hmmm… When I’ve tried exporting as XML or Adobe Tagged Text, the character styles don’t save with the text.

And while I can make text files with all tags and characters I can’t import them via a script.

Most of the non-text characters hace enumerators defined. For example:

tell application id "com.adobe.InDesign" -- Adobe InDesign 2022.app
	tell document 1
		set contents of insertion point 4 of parent story of text frame 1 to end nested style
	end tell
end tell

I’ve made some good progress. This script takes a data sample, which has all the variations of the style changes made, and drops them into the first text frame of an ID document. Using nested style sheets and GREP style sheets it gets all the formatting perfect. Next I’ll try to use it to populate a table.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set endStyleChar to ""
set myText to {¬
   {"Entertainment Tonight ", "Hip Hop Awards. (N) Å"}, ¬
   {"Survivor ", "(TVPG) Castaways stumble upon a sneaky advantage that comes at a great risk. (N)"}, ¬
   {"Tough as Nails ", "(TVPG) (Season premiere) Twelve new contestants arrive and their first challenge is to race to receive cargo dropped from a C-130 plane. (N) Å"}, ¬
   {"CSI: Vegas ", "(TV14) (Premiere) An attack on Jim Brass kicks off a twisted conspiracy targeting the Las Vegas crime lab. (N) Å"}, ¬
 {"", "Paid program"}, ¬
   {"News ", "Å"}, ¬
   {"Enemy of the State ", " ››› (1998) Will Smith, Gene Hackman. A former NSA operative aids the innocent victim of a politically motivated assassination cover-up. (R) Å"} ¬
      }
set readyText to {}
repeat with thisLine in myText
   set thisTitle to item 1 of thisLine as text
   set thisDesc to item 2 of thisLine as text
   set thisShow to thisTitle & endStyleChar & thisDesc
   set the end of readyText to thisShow
end repeat
set AppleScript's text item delimiters to {return}
set readyText to readyText as text
tell application "Adobe InDesign 2021"
   activate
   tell its document 1
      tell its text frame 1
         set contents to readyText
            end tell
   end tell
end tell

Basically, you style everything in your table, then export it as tagged text.

Then you can open that exported file in a text editor and inspect it.

You can delete most everything after the special tagged text file header and before the table start tags. This deleted stuff has style definitions, color definitions, etc., but we dont need them because when we import a file, we already have styles defined for everything.

So after seeing how the tags work in the exported tagged text file, you can identify where your variable data strings are and make table templates, row templates, cell templates, etc, and substitute your data into the surrounding table structure tags. I do it in Filemaker, but I guess other databases would work too.

If you want more details we’d probably have to correspond. Here’s a crude example. It should give an error on import as tagged text because the InDesign file isn’t there, but you should get a table:

<tStart:9,4:1:0><coStart:><coStart:><coStart:><coStart:><rStart:>RegionJanuaryFebruaryMarch<rStart:>North<clStart:1,1>1<clStart:1,1>2<clStart:1,1>3<rStart:>East<clStart:1,1>4<clStart:1,1>5<clStart:1,1>6<rStart:>West<clStart:1,1>7<clStart:1,1>8<clStart:1,1>9<rStart:>Sputh<clStart:1,1>10<clStart:1,1>11<clStart:1,1>12<rStart:>Northeast<clStart:1,1>13<clStart:1,1>14<clStart:1,1>15<rStart:>Northwest<clStart:1,1>16<clStart:1,1>17<clStart:1,1>18<rStart:>Southeast<clStart:1,1>19<clStart:1,1>20<clStart:1,1>21<rStart:>Soithwest<clStart:1,1>22<clStart:1,1>23<clStart:1,1>24

I think the text got cut off. Here’s an upload:

tagged-table-test.txt.zip (1.0 KB)