I am trying to use Applescript to automate the application of style sheets to text with certain tags.
Here is something I am trying to use but I can’t seem to extract the first character position from my search result to a number that I can then use with a second search result to make a range of characters. Here is what I have tried:
tell application "Adobe InDesign CS2"
activate
set find preferences to nothing
set change preferences to nothing
tell document 1
set stylefind to "<BR1>"
set stylefind2 to "</BR1>"
set myitem1 to (search for stylefind)
set myitem2 to (search for stylefind2)
select (text from myitem1 to myitem2)
end tell
end tell
I want the writers of the text to insert simple tags like this:
“Some sample text to show how I expect to apply styles, blahh blahh blahh…”
There may be others as well if you search for find/replace in the forums.
If I were you I would look into Adobe’s tagged text format as well for tagging text files that apply styles when imported. Since the file will need to be built to support this is not a typical word processor file you might want to have your editors write with simplified tags that you can do a search/replace on before sending it to production.
I have seen both those two macscripter links but I cannot seem to work out how to get a range based on two finds. It would be great if I could use a wildcard but CS2 does not seem to support GREP.
Something like “*” but this does not work.
I thought about Indesign tagged text but it is so complicated looking, I want editors to use this and for them to insert these long tags would not go down well.
I am interested in your XML suggestion, I will look into that.
tell application "Adobe InDesign CS3"
tell document 1
set theStory to parent story of text frame 1
tell theStory
set theText to text 1
set stylefind to "<BR1>"
set stylefind2 to "</BR1>"
set xx to offset of stylefind in theText
set xx to xx + 4
set yy to offset of stylefind2 in theText
set yy to yy - 1
set theRange to object reference of text from character xx to character yy of text 1
set font style of theRange to "Bold"
end tell
end tell
end tell
You can then delete the tags using the same parameters.