Indd CS vs. CS2 Selected Text

Can somebody “PLEASE” help me out with this?

In CS, this snippet below would have worked. Take this example: I type the numbers “123456789” in a text frame. If I were to then highlight from “2-9” and run the script, the script would have removed all those characters in CS. But now in CS2 it is not. I have checked properties, and do not see any difference between the old and new? I don’t know much :frowning:
-Jeff

tell application "Adobe InDesign CS2"
	try
		set theSelection to selection
		if theSelection is not {} then
			set theObj to item 1 of selection
			set theClass to class of theObj
			if theClass is in {string, insertion point} then delete theSelection
			if theClass is not in {string, insertion point} then return
		end if
	end try
end tell

two things one try telling document 1
second what is the error you get ?

It is not so much that I am getting an error. It is that the script won’t delete the selected text.
For instance, this is the event log for CS2:

tell application “Adobe InDesign CS2”
get selection of document 1
{text from character 2 to character 9 of text flow id 170 of document “Untitled-4”}
get item 1 of selection of document 1
“23456789”
end tell

And this is the event log for CS:

tell application “InDesign CS”
get selection of document 1
{text from character 2 to character 10 of text flow id 304 of document “Untitled-1”}
get item 1 of selection of document 1
"23456789
"
delete {text from character 2 to character 10 of story id 304 of document “Untitled-1”}
end tell

Can you help me out?

this seems to work


tell application "Adobe InDesign CS2"
	set theSelection to selection
	if theSelection is not {} then
		set theClass to class of selection
		if theClass is text then
			delete theSelection
		else
			return
		end if
	end if
end tell

Many Thanks!
This is working great.

Now I have another issue, that must be related to my system and its fonts. Somehow it doesn’t like “Helvetica”. If I switch helvetica with Myriad the script works? But where it once used to pick up Helvetica fine using CS, it now is not? Is this a known issue? No worries if you don’t want to answer. You have helped me tremendously.

-Jeff

tell application "Adobe InDesign CS2"
	set theSelection to selection
	if theSelection is not {} then
		set theClass to class of selection
		if theClass is text then
			delete theSelection
		else
		end if
	end if
	
	
	try
		set theInsert to insertion point 1 of selection
		set thefill to fill color of theInsert
	end try
	try
		set theInsert2 to insertion point 2 of selection
		set thefill to fill color of theInsert2
	end try
	try
		set theInsert to insertion point 1 of selection
		set thefill to fill color of theInsert
		set fontHelvetica to "Helvetica"
		set properties of theInsert to {applied font:fontHelvetica, point size:6, font style:"Medium", capitalization:normal, horizontal scale:100, vertical scale:100, stroke weight:0, stroke color:"None", fill color:thefill}
		set contents of theInsert to "With "
		set theItalic to insertion point 1 of selection
		set properties of theItalic to {font style:"Italic"}
		set contents of theItalic to "Mailer"
		set theSuper to insertion point 1 of selection
		set fontRef to "Myriad Pro"
		set properties of theSuper to {applied font:fontRef, font style:"Regular"}
		set contents of theSuper to "®"
		set theCouponOnly to insertion point 1 of selection
		set fontHelvetica to "Helvetica"
		set properties of theCouponOnly to {applied font:fontHelvetica, point size:6, font style:"Medium", capitalization:normal, horizontal scale:100, vertical scale:100, stroke weight:0, stroke color:"None", fill color:thefill}
		set contents of theCouponOnly to " Coupon Only"
	end try
end tell


ahh helvetica in my opinion a nightmare if want to throw that font away and never see it again most of the work I do in indesign is done in 2.0 so I have not had the pleasure of dealing with fonts yet but have fought and continue to fight the font battle … I’ll take a look when I have time but I can’t promise anything when it comes to dealing with fonts

remember font is a four letter word. :wink:

mm

Tell me about it:mad:

We have had trouble with Helvetica since day 1. But we are pretty much stuck with it because it is used on so many of our templates.

In this instance I “may” be allowed to use Myriad Pro. But getting Helvetica to work would be ideal, especially down the road.

Thank you again for all that you have done.

-Jeff

Hi jeffkr

Try something like this on some selected “Helvetica” that you need it to be:

tell application "Adobe InDesign CS2"
	tell document 1
		get name of font 1 --"Helvetica CY	Regular"
	end tell
end tell

What you get in your result window is what you need to paste into your script, i know that the style is included in the string so you will have to play around with that in your script.
I added the result of the above script to yours and it picked up the helvetica font:

tell application "Adobe InDesign CS2"
	set theSelection to selection
	if theSelection is not {} then
		set theClass to class of selection
		if theClass is text then
			delete theSelection
		end if
	end if
	
	
	try
		set theInsert to insertion point 1 of selection
		set thefill to fill color of theInsert
	end try
	try
		set theInsert2 to insertion point 2 of selection
		set thefill to fill color of theInsert2
	end try
	try
		set theInsert to insertion point 1 of selection
		set thefill to fill color of theInsert
		set fontHelvetica to "Helvetica CY	Regular"
		set properties of theInsert to {applied font:fontHelvetica, point size:50, font style:"Medium", capitalization:normal, horizontal scale:100, vertical scale:100, stroke weight:0, stroke color:"None", fill color:thefill}
		set contents of theInsert to "With "
		set theItalic to insertion point 1 of selection
		set properties of theItalic to {font style:"Italic"}
		set contents of theItalic to "Mailer"
		set theSuper to insertion point 1 of selection
		set fontRef to "Myriad Pro"
		set properties of theSuper to {applied font:fontRef, font style:"Regular"}
		set contents of theSuper to "®"
		set theCouponOnly to insertion point 1 of selection
		set fontHelvetica to "Helvetica CY	Regular"
		set properties of theCouponOnly to {applied font:fontHelvetica, point size:50, font style:"Medium", capitalization:normal, horizontal scale:100, vertical scale:100, stroke weight:0, stroke color:"None", fill color:thefill}
		set contents of theCouponOnly to " Coupon Only"
	end try
end tell


good luck.

Fonts don’t you just love em!! :confused:

pidge1,
That little tidbit of information to get the font name is EXTREMELY helpful. I would never have though about doing that! Ironically, I did some searching prior to your post and learned that the name of Helvetica Medium is equal to “Helvetica” + “tab” + “Medium”. Bizarre but true. And your return font script did throw back that same name. Hence your advice to copy and paste the name is very important, for it could look like a space for those novices like me.

This forum post was extremely helpful today and in the past. Thank you everyone for your excellent advice and input.

As for Fonts. you can’t live with them, and can’t live without them :slight_smile:

-Jeff