Indesign Search

Dear all,

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"
	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…”

Has anyone any ideas?


David Lee

You might want to take a look at this thread:


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.

For more information see:

You might also want to look into an XML workflow where you import the text as XML.

You could code this, but why reinvent the wheel if it is not needed.

Thanks for your reply Jerome.

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.

So do you know how to complete this applescript?

Many thanks,

David Lee

This works for me:

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.

Hi JimOneill,

Thank you very much, that works perfectly.

It really amazes me when I get a response like this on a forum.

Thanks again,

David Lee

Well, this isn’t just any forum…