Indesign CS - problem finding wildcards & changing attributes

Hi… I’m hoping someone might have experienced & fixed this before or can point out what I’m doing wrong.

What I am trying to do is find all instances in my document where the paragraph style is “SB Item# Bold” and where there are 5 or more characters (any mixture of digits and text (with the possibility of spaces also)) that precede a TAB. When an instance is found I want to turn it’s underline and underline overprint properties “ON” and turn the text’s font color to “Border CMYK 2”

What is happening however is that only instances where there are exactly 5 characters preceding the tab are being marked. If there are 6 or more characters preceding the tab, that tab and the “5” characters preceding it are not caught & marked. (My test document that I’ve been trying this on has 8 unlinked textboxes with various amounts of text preceding the tab). :confused:

Would someone be so kind as to point out what I am doing wrong here?

tell application "InDesign CS"
	activate
	set searchWhat to active document
	set findAttributes to {find text:"^?^?^?^?^?^t", underline:false, underline overprint:false, applied paragraph style:"SB Item# Bold", applied character style:"[Any Style]", whole word:false}
	set changeAttributes to {underline:true, underline overprint:true, fill color:"Border CMYK 2"}
	display dialog (count of (search searchWhat with find attributes findAttributes)) -- this line is part of my debugging process 
	search searchWhat with find attributes findAttributes with change attributes changeAttributes
end tell

ps - I’ve removed the “deleted text” problem from the above as it has been resolved… seems to be a Script Debugger issue where the problem only happens if I havent saved the script as something yet.

I just took a quick look at your code. My guess, and I have not played around with this, is that because you have 5 wild card characters it is only dealing with the lines that have that many characters. You could do a repeat loop, changing the number of wild cards up to 5 each time through the loop.

Thanks for the suggestion Jerome. However my problem is that I need to identify occurence of 5 or more characters preceding a tab to indicate where I need one less tab in that part of a line to prevent over-tabbing. I cant remove tab stops because certain situations call for them and I have no way of knowing how much text will precede a tab thus checking for every type of situation will be very time consuming.

Lastly, I am hoping your comment that Indesign is looking for lines that contain only the exact number of characters as wildcards used is wrong as that will present major challenges for me later on when I need to look for pricing (using wildcards) to insert decimals or commas for French or English format where the length of the prices differs.

So, if I understand this right, you have a paragraph with a variable number of characters before the first tab. You need to determine those paragraphs that have more than 4 characters (I read your post worng the first time) before the tab and apply a certain paragraph style to it. Like most things there are more than one ways to skin a cat:

tell application "InDesign CS"
	activate
	tell document 1
		set thestories to every story
		repeat with i from 1 to count of every story
			set z to count of every paragraph of story i
			repeat with x from 1 to z
				if contents of paragraph x of story i contains "	" then
					set taboffset to (index of first character of paragraph x of story i whose contents is "	")
					set paroffset to index of first character of paragraph x of story i
					if taboffset - paroffset ≥ 5 then
						set properties of characters 1 through (taboffset - paroffset) of paragraph x of story i to {underline:true, underline overprint:true, fill color:"Border CMYK 2"}
					end if
				end if
			end repeat
		end repeat
	end tell
end tell

I guess I was really hoping to find a solution where indesign would hunt for all occurences of the wildcard indicators using the “search searchWhat with find attributes findAttributes with change attributes changeAttributes” statement without requiring that the length of the word/text preceding the tab precisely match the number of wild card characters (that would have worked nicely with my search & replace library function). However your script does the job so I’ll adjust & embed it as required and go from there.

Thank you very much for your help Jerome, much appreciated.
Len :slight_smile: