InDesign CS3 Paragraph Style won't script while inside a Style Group?

I have a code that applies a paragraph style to a search string:



tell application "Adobe InDesign CS3"
	activate
	tell parent story of item 1 of selection

--This is the command:
try
	set (properties of every paragraph whose contents begins with ("HelloYall" & (ASCII character 13))) to {applied paragraph style:"My Paragraph Style"}
end try

end tell
end tell

It works.

The problem is that it DOESN’T work when I place that paragraph style INSIDE of a style group folder (looks like a folder) in the Paragraph Style panel window.

How do I address a style sheet inside of a style group?

You have to tell the style group that you want to use it’s paragraph style.


tell application "Adobe InDesign CS3"
	activate
set theDoc to the active document
	set pGroups to paragraph style groups of theDoc
	set myStyleGroup to item x of pGroups -- where x is the number of the style group you want to use, otherwise the format is "paragraph style group id #### of document "Your Doc"
	tell myStyleGroup
		set yallStyle to "My Paragraph Style"
	end tell
	tell parent story of item 1 of selection
		
		--This is the command:
		try
			set (properties of every paragraph whose contents begins with ("HelloYall" & (ASCII character 13))) to {applied paragraph style:yallStyle}
		end try
	end tell
end tell

Thank you. I was able to get it to work with the ID number. Since I have several different machines that are using this script and style sheets AND the paragraph group ID numbers are different on the different machines, I wrote this little script to grab it based on its name. Works like a charm with my original.


tell application "Adobe InDesign CS3"
	activate
	
	--Scan and search for p. style groups...
	set pGroups to paragraph style groups of the active document
	repeat with i from 1 to (count of items in pGroups)
		set myStyleGroup to the id of item i of pGroups
		
		--scan each p style group for paragraph styles	
		repeat with j from 1 to (count of paragraph styles in item i of pGroups)
			set disname to name of paragraph style j of item i of pGroups
			
			--test the name of the current qued p. style 
			--and apply an much easier to reference string name for later
			if disname = "The Actual Style Name" then set TheStyleName to paragraph style j of paragraph style group id myStyleGroup of the active document
			
		end repeat
	end repeat


   tell parent story of item 1 of selection

--This is the command:
try
   set (properties of every paragraph whose contents begins with ("HelloYall" & (ASCII character 13))) to {applied paragraph style:TheStyleName}
end try

end tell
end tell