InDesign CS2: Set tracking of single character w/ applescript

hi,

i did a bit of searching before posting this and couldn’t find anything that matched my problem.

i have a data merge template made for creating signs (on us letter) and i want to use applescript to set the tracking of a single character to -100 due to the kerning in the font itself. i have done some very basic applescript, mostly for osx itself and have read some of the ID CS2 scripting guide.

is it possible to select all the “1” characters (limited to a specific font) throughout the document and apply -100 tracking to them?
at the moment i am doing it manually and it can take a bit of time, depending on how many signs are produced.

i can post an example .indd file if needed.

thanks.

Hi Prof

I haven’t had chance to finish this but someone else maybe able to add to or fill in the blanks but this bit should get you your “1”'s and
your kerning…
Not sure when i can have another look at it…

tell application "Adobe InDesign CS2"
	activate
	tell document 1
		tell text frame 1
			repeat with i from 1 to count of paragraphs
				tell paragraph i
					repeat with j from 1 to count of characters
						if character j = "1" then
							set t to j
							tell character t
								set kerning method to "none"
								set kerning value to -100
							end tell
						end if
					end repeat
				end tell
			end repeat
		end tell
	end tell
end tell

worked for me on a small paragraph fullof text with one’s dotted here and there…

looks like it will do just what i need.
is there a way to limit the changes to a specific font? the dates on these signs uses a different font that doesn’t have the kerning issue, so i don’t want to add the -100 attribute to these, only the 1s set in the specific font (Futura BT).

i’ll give your script a run, thanks for your help.

Hi Prof

Don’t have indesign on my home machine! Wrote the script at work where i have it, but didn’t have time to finish it, i’m sure the function your after with the font
can be scripted, i’ll try and have a look at it tomorrow if i can.

Somebody else may step in, in the meantime and help you out…

i just tried it out and the kerning isn’t affecting the “1” character. i tried changing kerning to tracking but it doesn’t seem to have an effect.
yep, double checked it to be sure and it isn’t affecting the text.

are you running the script from the scripts palette or the Script Editor?
perhaps there is something i am doing wrong, but i am putting the script in the Scripts folder and running it from the scripts palette, and nothing.
maybe kerning isn’t the right method for this task? i use the Tracking box in the toolbar at the top of the screen to set the -100 Tracking.

Hi Prof

Just running from script editor.
i was seeing my results in the type pallette not the menu bar…
are we getting tracking aqnd kerning mixed up.
it was definetly the kerning which i used in the script…
Not sure on tracking, graphics in these adobe programs is my strong point don’t deal with altering text to much…

A slight revision to the above script:

tell application "Adobe InDesign CS2"
	--activate
	tell document 1
		tell text frame 1
			repeat with i from 1 to count of paragraphs
				tell paragraph i
					repeat with j from 1 to count of characters
						set t to contents of character j
						if t = "1" then
							if name of applied font of character j is "Arial	Regular" then
								tell insertion point 2 of character j
									set kerning method to "none"
									set kerning value to -100
								end tell
							end if
						end if
					end repeat
				end tell
			end repeat
		end tell
	end tell
end tell

Problems that I saw were that you need to test the contents of character j for the value not the character itself. I changed to setting the kerning value to the insertion point so that the placemnet is targeted, point 1 is before the character and 2 is after the character. I also added in an if statement to check the font so that it only applies to the one that you are looking for, in this case Arial Regular.

i tried the above script from Jerome but still have no results when running the script. I am linking to an example file which I would want to run the script on. I want to be able to generate my signs (currently working) then run this script to set all the “1” characters to Tracking: -100 to close up a gap between the “1” and other numbers.

you can find the example file here:
Example .indd file

Hi Prof

Test this on your file for me.
I had problem with baskerville font but seemed to run okay…

tell application "Adobe InDesign CS2"
	activate
	tell document 1
		repeat with k from 1 to count of text frames
			tell text frame k
				repeat with i from 1 to count of paragraphs
					tell paragraph i
						repeat with j from 1 to count of characters
							if character j = "1" then
								set t to j
								tell character t
									set kerning method to "none"
									set kerning value to -100
								end tell
							end if
						end repeat
					end tell
				end repeat
			end tell
		end repeat
	end tell
end tell

might take a while if theys a lot of characters

Pidge, are you using CS1? yours isn’t working for me eihter. Here is a revised solution to the problem though which should work.

tell application "Adobe InDesign CS2"
	tell document 1
		set theCharacters to object reference of every character of every text frame whose contents is "1"
		repeat with i from 1 to count of theCharacters
			if name of applied font of item i of theCharacters is "Futura Std	Bold" then
				tell insertion point 2 of item i of theCharacters
					set kerning method to "none"
					set kerning value to -100
				end tell
			end if
		end repeat
	end tell
end tell

I had to replace the fonts to work with the document. You will need to replace the name of the font that I used with the proper name in that InDesign is using for your font. An easy way to get that is running the following script then coly and past the right font name into the other script.

tell application "Adobe InDesign CS2"
	tell document 1
		set x to name of every font
	end tell
end tell

This did work on my copy of InDesign CS2.

You could also do this which might be slightly faster:

tell application "Adobe InDesign CS2"
	tell document 1
		set theCharacters to object reference of every character of every text frame whose contents is "1" and name of applied font is "Futura Std	Medium"
		repeat with i from 1 to count of theCharacters
			tell insertion point 2 of item i of theCharacters
				set kerning method to "none"
				set kerning value to -100
			end tell
		end repeat
	end tell
end tell

Hi jerome

I’m running CS2.
i didn’t get an error when i run mine and it seemed to work…
i have got about 20 jobs on the go at the minute so mind not in the right place…

cheers

Actually this is all you should need:

tell application "Adobe InDesign CS2"
	tell document 1
		set theCharacters to object reference of every character of every text frame whose contents is "1" and name of applied font is "Futura Std	Medium"
		repeat with i from 1 to count of theCharacters
			set kerning value of insertion point 2 of item i of theCharacters to -100
		end repeat
	end tell
end tell

There shouldn’t be a reason to set the kerning method since that is altered by setting the custom value. This method, providing that you have the name of the font the way that InDesign returns it will process Profs sample document in well under 1 second on my G5 PM.

Do you have it working yet Prof?