Replacing paragraph styles - Problem with styles in folders

I came across the following script to find and replace paragraph styles, which works perfect if the styles are sitting at the first level within the list of paragraph styles. The problem I having is that the document I’m working with has folders within folders of paragraph styles.

How can I update the following code to reference a paragraph style within folders? The style is placed in the following folder - Amended Styles > Body > Body Text half amended


set DeleteList to {"Body Text half"}
set ReplaceList to {"Body Text half amended"}

tell application "Adobe InDesign CS6"
	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
	end tell
end tell

This is what I’ve tried so far but failed miserably


set DeleteList to {"Body Text half"}
set ReplaceList to {"Body Text half amended"}

tell application "Adobe InDesign CS6"
	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 StandardStyle to paragraph style item x of ReplaceList of paragraph style group "Body" of paragraph style group "Amended Styles" of document 1
								set applied paragraph style of paragraph CurrentParagraph to StandardStyle
							end if
						end repeat
					end if
				end repeat
			end tell
		end repeat
	end tell
end tell

Hi Evan,

This should do the trick:

set DeleteList to {"Body Text half"}
set ReplaceList to {"Body Text half amended"}

tell application "Adobe InDesign CS6"
	activate
	tell document 1
		set MyStories to every story
		repeat with StoryCount from 1 to (count of MyStories)
			set thisStory to item StoryCount of MyStories
			repeat with CurrentParagraph from 1 to count of paragraphs of thisStory
				set ParStyle to name of applied paragraph style of paragraph CurrentParagraph of thisStory
				set AppliedParStyle to applied paragraph style of paragraph CurrentParagraph of thisStory
				if ParStyle is in DeleteList then
					repeat with x from 1 to count of DeleteList
						if item x of DeleteList is ParStyle then
							set styleToApply to paragraph style (item x of ReplaceList) of paragraph style group "Body" of paragraph style group "AMENDED STYLES"
							set applied paragraph style of paragraph CurrentParagraph of thisStory to styleToApply
						end if
					end repeat
				end if
			end repeat
		end repeat
	end tell
end tell

If you need any further assistance then please PM me.

Thanks,
Nik