InDesign manipulated text doesn't hold case

I have a script to manipulate a story of text listings in InDesign, but it wipes out the text case in every place where it should be All caps and turns it into Title case.

How can I set things to preserve the case of the text as it stands in the InDesign story?


tell application "Adobe InDesign CS5"
	set enable redraw of script preferences to false
	set find text preferences to nothing
	set case sensitive of find change text options to false
	set include footnotes of find change text options to false
	set include hidden layers of find change text options to false
	set include locked layers for find of find change text options to true
	set include locked stories for find of find change text options to true
	set include master pages of find change text options to false
	set whole word of find change text options to false
	
	set myTextObjects to {text style range, paragraph, text column, text, story}
	if (count documents) > 0 then
		set mySelection to parent story of selection
		set SelectProps to properties of selection
		return SelectProps
		return mySelection
		if (count mySelection) > 0 then
			if class of item 1 of mySelection is in myTextObjects then
				tell document 1
					set targetFrame to text frame 1 of the page 3
					--return targetFrame
					
					set myText to contents of item 1 of mySelection
					--return (count paragraphs of myText)
					--return myText
					set myNewText to ""
					repeat with i from (count paragraphs of myText) to 1 by -1
						set workPara to paragraph i of myText
						--return workPara
						try
							set work2Para to paragraph (i - 1) of myText
							--return work2Para
						on error
							set work2Para to ""
						end try
						if workPara = work2Para then
							set workPara to ""
							
						end if
						set myNewText to workPara & return & myNewText
						
					end repeat
					tell parent story of targetFrame
						--delete paragraphs
						set contents of targetFrame to myNewText
					end tell
					
				end tell
			else
				display dialog "Text is not selected, or too little text is selected. Please select several paragraphs and try again."
			end if
		else
			display dialog "Nothing is selected. Please select some text and try again."
		end if
	else
		display dialog "No documents are open. Please open a document and try again."
	end if
	

If I read this correctly you are replacing the text in targetFrame with the new text in the variable myNewText. When you do this the new text takes on the paragraph and character stylings of the first character in the text flow.

If you want to maintain the styling in the document then it might be best to delete the paragraphs as yo go instead of flowing new text.

That’s OK, because I have a specific Paragraph style set for the entire listing. The case setting for that style is Normal, so it shouldn’t affect anything.

What’s odd, after further review, is that most words that are all Caps before the first tab stayed OK, but all the State abbreviations, which are after the first tab, turned from All Caps (they were made caps via find/replace before the script ran) to Title case. The same happened to most directions (NW, NE, etc., now Nw, Ne).