Noobie: Script to stylize text in InDesign

Hi I’m very new at this.

I’m trying to find a way to get InDesignCS2 to apply an existing Paragraph Style to newly imported text in a text frame in an open document. I’m running OSX3.9 Panther. I found a run-only script that will work for OSX4, but I don’t have OSX4. Any tips would be appreciated.

Thanks,
Kevin

This is a script for InDesign CS to format basic information (Company Name, slogan, address, phone number & email); but it should give you a place to start. It gets the names of all the paragraph styles and applies them depending on how many paragraphs there are and whether there is an email address. Send me an email if I may be of further assistance. ~Michelle

tell application "InDesign CS"
	if not (exists active document) then
		display dialog ¬
			"No InDesign files are open. Press any key to continue or any other key to erase your hard drive." buttons {"OK"} ¬
			default button "OK" with icon "warning"
		return
	end if
	set theDoc to the active document
	set pCount to count of paragraph styles of theDoc
	if pCount > 1 then
		set pStyles to the name of paragraph styles of theDoc whose name is not "[No paragraph style]"
		set pCount to (pCount - 1)
		repeat with i from 1 to (pCount)
			set AppleScript's text item delimiters to " "
			set L to (pStyles) as string
		end repeat
	end if
	tell theDoc
		set pStyles to the name of paragraph styles of theDoc whose name is not "[No paragraph style]"
		set sCount to count of pStyles
		set aName to item 1 of pStyles as string
		set bName to item 2 of pStyles as string
		set cName to item 3 of pStyles as string
		set dName to item 4 of pStyles as string
		if sCount = 5 then
			set eName to item 5 of pStyles as string
		else
			set eName to ""
		end if
--we have multiple templates, so the paragraph styles aren't consistent and couldn't be named directly
		set aTest to {"address", "plain"}
		set bTest to {"italic", "product"}
		set cTest to {"main", "company"}
		set dTest to {"phone", "bold"}
		set eTest to {"email"}
		repeat with i from 1 to (sCount)
			set thisTest to item i of pStyles as string
			if aTest contains first word of (thisTest) then
				set plainStyle to paragraph style (thisTest) of the theDoc
			else if bTest contains first word of thisTest then
				set italicStyle to paragraph style (thisTest) of the theDoc
			else if cTest contains first word of thisTest then
				set mainStyle to paragraph style (thisTest) of the theDoc
			else if dTest contains first word of thisTest then
				set phoneStyle to paragraph style (thisTest) of the theDoc
			else if eTest contains first word of thisTest then
				set emailStyle to paragraph style (thisTest) of the theDoc
			end if
		end repeat
	end tell
	tell theDoc
		repeat with i from 1 to (count text frames)
			set theContents to the contents of text frame i
			if the (count of the paragraphs of theContents) ≥ 2 then
				set thisFrame to text frame i
				set theContents to the contents of thisFrame
				set parCount to (count of the paragraphs of theContents)
				set a to the 1st paragraph of theContents
				set b to the 2nd paragraph of theContents
				if parCount > 2 then set c to the 3rd paragraph of theContents
				if parCount > 3 then set d to the 4th paragraph of theContents
				if parCount > 4 then set e to the 5th paragraph of theContents
				if parCount = 2 then
					tell the 1st paragraph of theContents
						apply style using (mainStyle) without clearing overrides
					end tell
					if b contains "@" then
						set b to (a reference to the 2nd paragraph of thisFrame)
						tell b
							apply style using (emailStyle) without clearing overrides
						end tell
					else
						tell the 2nd paragraph of theContents
							apply style using (phoneStyle) without clearing overrides
						end tell
					end if
				else
					if parCount = 3 then
						tell the 1st paragraph of theContents
							apply style using (mainStyle) without clearing overrides
						end tell
						if b contains "@" then
							set b to (a reference to the 2nd paragraph of thisFrame)
							tell b
								apply style using (emailStyle) without clearing overrides
							end tell
						else
							tell the 2nd paragraph of theContents
								apply style using (plainStyle) without clearing overrides
							end tell
						end if
						if c contains "@" then
							set c to (a reference to the 3rd paragraph of thisFrame)
							tell c
								apply style using (emailStyle) without clearing overrides
							end tell
						else
							tell the 3rd paragraph of theContents
								apply style using (phoneStyle) without clearing overrides
							end tell
						end if
					else
						if parCount = 4 then
							tell the 1st paragraph of theContents
								apply style using (mainStyle) without clearing overrides
							end tell
							if b contains "@" then
								set b to (a reference to the 2nd paragraph of thisFrame)
								tell b
									apply style using (emailStyle) without clearing overrides
								end tell
							else
								tell the 2nd paragraph of theContents
									apply style using (italicStyle) without clearing overrides
								end tell
							end if
							if c contains "@" then
								set c to (a reference to the 3rd paragraph of thisFrame)
								tell c
									apply style using (emailStyle) without clearing overrides
								end tell
							else
								tell the 3rd paragraph of theContents
									apply style using (plainStyle) without clearing overrides
								end tell
							end if
							if d contains "@" then
								set d to (a reference to the 4th paragraph of thisFrame)
								tell d
									apply style using (emailStyle) without clearing overrides
								end tell
							else
								tell the 4th paragraph of theContents
									apply style using (phoneStyle) without clearing overrides
								end tell
							end if
						else
							if parCount = 5 then
								tell the 1st paragraph of theContents
									apply style using (mainStyle) without clearing overrides
								end tell
								if b contains "@" then
									set b to (a reference to the 2nd paragraph of thisFrame)
									tell b
										apply style using (emailStyle) without clearing overrides
									end tell
								else
									tell the 2nd paragraph of theContents
										apply style using (italicStyle) without clearing overrides
									end tell
								end if
								if c contains "@" then
									set c to (a reference to the 3rd paragraph of thisFrame)
									tell c
										apply style using (emailStyle) without clearing overrides
									end tell
								else
									tell the 3rd paragraph of theContents
										apply style using (plainStyle) without clearing overrides
									end tell
									if d contains "@" then
										set d to (a reference to the 4th paragraph of thisFrame)
										tell d
											apply style using (emailStyle) without clearing overrides
										end tell
									else
										tell the 4th paragraph of theContents
											apply style using (phoneStyle) without clearing overrides
										end tell
									end if
									if e contains "@" then
										set e to (a reference to the 5th paragraph of thisFrame)
										tell e
											apply style using (emailStyle) without clearing overrides
										end tell
									else
										tell the 5th paragraph of theContents
											apply style using (phoneStyle) without clearing overrides
										end tell
									end if
								end if
							end if
						end if
					end if
				end if
			end if
		end repeat
	end tell
end tell

Model: G4
AppleScript: 1.9.3
Browser: Safari 312.3.1
Operating System: Mac OS X (10.3.9)