InDesign -- replacing character and paragraph styles with other styles

Hi all-

I’m trying to use AS to find text that has a particular paragraph style applied to it, and apply a different paragraph style to that text. Same for character styles. I need to do this several times in the same document. We’re importing an InCopy doc that has its own styles applied, and I need a quick way to map the new (and differently named, of course) styles to the imported text.

Here’s an example of what I’m doing. I have to repeat this line for every change, and sometimes the script just stops:

search with find attributes {applied paragraph style:“¢BMStratTxt”} with change attributes {applied paragraph style:“SB_Strat_Txt”}

Additionally, once the script is run, I have to quit InDesign and relaunch before it will work again.

There’s gotta be a more elegant way to do this. I’ll post the entire script below.

I’m running Indesign CS 3.0.1 (CS2 compatibility patch has not been applied)
Mac OS X 10.3.8 (can’t update, I.T. won’t let me)
AppleScript 1.9.3

Any suggestions would undoubtedly make the universe a slightly better place.

----script follows----

tell application “InDesign CS”
activate

tell the active document
	
	search with find attributes {applied paragraph style:"¢BMStratTxt"} with change attributes {applied paragraph style:"SB_Strat_Txt"}
	
	search with find attributes {applied paragraph style:"¢BMVocabWords"} with change attributes {applied paragraph style:"SB_Vocab_List"}
	
	search with find attributes {applied paragraph style:"¢BMVocStrat"} with change attributes {applied paragraph style:"SB_VocStra_Head"}
	
	search with find attributes {applied paragraph style:"¢WowTxt"} with change attributes {applied paragraph style:"Txt_Lsn_Intro"}
	
	search with find attributes {applied paragraph style:"¢LesHeadA"} with change attributes {applied paragraph style:"Head_A"}
	
	search with find attributes {applied paragraph style:"¢FocusQuest"} with change attributes {applied paragraph style:"SB_FocusQues"}
	
	search with find attributes {applied paragraph style:"¢HeadB"} with change attributes {applied paragraph style:"Head_B"}
	
	search with find attributes {applied paragraph style:"¢RevQuest"} with change attributes {applied paragraph style:"Txt_Review"}
	
	search with find attributes {applied paragraph style:"¢WYLTxt"} with change attributes {applied paragraph style:"WYLBoxTxt"}
	
	search with find attributes {applied paragraph style:"¢LRNumList"} with change attributes {applied paragraph style:"LRBoxTxtList"}
	
	search with find attributes {applied paragraph style:"¢Txt"} with change attributes {applied paragraph style:"Txt"}
	
	search with find attributes {applied character style:"¢Highlight"} with change attributes {applied character style:"Highlight"}
	
	search with find attributes {applied character style:"¢ReviewSkill"} with change attributes {applied character style:"Skill_Label"}
	
	search with find attributes {applied character style:"¢Bold"} with change attributes {applied character style:"Bold"}
	
	search with find attributes {applied character style:"¢LRBlu"} with change attributes {applied character style:"LRBoxLeadInBlu"}
	
	search with find attributes {applied character style:"¢Red"} with change attributes {applied character style:"LRBoxLeadInRed"}
	
	set right indent of paragraph style "¢Label" to 0
	
end tell

end tell
end

—end script----

Thanks all!

Eric Murray

I don’t know about more elegant, but it works pretty fast and without crashing:

set DeleteList to {"¢BMStratTxt", "¢BMVocabWords", "¢BMVocStrat", "¢WowTxt"}
set ReplaceList to {"SB_Strat_Txt", "SB_Vocab_List", "SB_VocStra_Head", "Txt_Lsn_Intro"}

tell application "InDesign CS"
	activate
	tell document 1
		set MyStories to every story
		repeat with StoryCount from 1 to (count of MyStories)
			tell (item StoryCount of MyStories)
				repeat with CurrentParagraph from 1 to count of paragraphs
					set ParStyle to name of applied paragraph style of paragraph CurrentParagraph
					if DeleteList contains ParStyle then
						repeat with x from 1 to count of DeleteList
							if item x of DeleteList is ParStyle then
								set applied paragraph style of paragraph CurrentParagraph to item x of ReplaceList
							end if
						end repeat
					end if
				end repeat
			end tell
		end repeat
		repeat with x from 1 to count of DeleteList
			try
				delete paragraph style (item x of DeleteList)
			end try
		end repeat
	end tell
end tell
beep

It’s raw, and to the point, something that I wrote reciently for work. You should be able to adapt it to character styles as well, I was replacing style names from text in an old Quark 3.32 job we were converting to InDesign with a new design and haven’t had any problems with this. Does the job on the documents I’m converting in 10-20 seconds on my 450 mhz Cube at home on a list of some 50 paragraph styles, and clears the “old” styles out of the document when it is done replacing them.

Thanks Jerome!

It works very well! I am still too much of an AS noob to rewire it for charStyles, but most of the heavy lifting is done on the paraStyles. Thanks again for the assistance!

Eric