InDesign CS3 find/replace

Howdy folks,

I’m painfully new to working in Applescript, so hopefully this will be an easy question.

I’m working in InDesign CS3 and I’m looking for a way to change the kerning on certain pairs of characters to avoid crashes. Unfortunately, the character pairs I need to fix are made up of one italic character and one roman character (i.e., and italic “f” followed by a roman “)”).

Is there a way to set up a script that is able to find such a combination? Alternatively, is there a way to get it to, perhaps, find an italic “f” and then utilize an if/then statement to determine if the italic “f” is followed by a roman “),” then adjust the kerning between the two?

I feel I’m pretty close to the latter method using the following:

tell application “Adobe InDesign CS3”
set find text preferences to nothing
set find what of find text preferences to “f”
set properties of find text preferences to {font style:“Italic”}
tell document 1
set myFoundItems to find text
repeat with i in myFoundItems
set selection to i
tell selection
end tell
end repeat
end tell
end tell

The only part I can’t figure out is how to extend the selected found text to include the next (and for other pairs, previous) character. If there’s a way to do that, I feel like I could put in the following code in the “tell selection” module:

set CharA to character 1 of selection
set CharB to character 2 of selection

if CharB is “)” then
set kerning value of selection to 200
end if

So basically, I guess I’m wondering whether or not there’s a way to select the next character, thereby enabling the script to search for italic f’s, select the following character on each iteration and run the little if/then to determine if that character is a roman closed paren, and adjust the kerning accordingly. I feel like it would go together with the “set selection to i” line in the first part, so that it’d read kinda like “set selection to i + next character,” but that didn’t work. :stuck_out_tongue:

Anyway, can anybody help me out? Thanks!


Oh no! Maybe it’s not as simple as I’d hoped.

I’ve found a pretty decent solution by integrating the second bit of code into a QuicKeys shortcut, but it still has to utilize the find/change dialog box in InDesign, so it’s not quite as streamlined as I’d prefer. Said shortcut finds an italic “f,” closes the find dialog, selects the next character, and runs the little if/then module.

The only trouble is I have to either trigger the shortcut multiple times or have it repeat a predetermined number of times, which will usually be not enough or too many. I guess the same is true of the script, but it would run much quicker without having to use any dialog boxes.

So, anybody got any suggestions? Thanks much!

What you want to do is not that hard, though finding the way probably is not that intuitive for someone new to working with Adobe’s object model and commands. The following works in ID CS2:

tell application "Adobe InDesign CS2"
	set find text of find preferences to "f)"
	set FoundText to search document 1
	repeat with anItem in FoundText
		if font style of character 1 of anItem is "Italic" then set kerning value of character 1 of anItem to 200
	end repeat
end tell

This will set the kerning value of the second insertion point of any italic “f” paired with a “)” to 200. I think that it is pretty self-explanatory but if you have any questions let me know.

Jerome! Thank you! :smiley:

I had to massage it a little bit for CS3, but I’ve got it working. And it looks like I can just string a bunch together to fix all my crashes in one fell swoop. This should save some time!

I really appreciate the help. Made my Monday! :slight_smile: