Applying next paragraph style in InDesign

Hi,

I have written a script that pulls text into a text box and successfully applies a paragraph style that is also defined in the script.

In the code that defines the paragraph style I also denote a ‘next style’. This all works properly and when I go to InDesign after running the script the text has the correct style applied to it and the style has the correct ‘next’ style and I can maually, in InDesign, select ‘Apply then Next style’

My problem is that I cannot ‘Apply then Next style’ from within the Applescript. It’s frustrating. Everything is there and everything works and I can do the apply manually in InDesign but how do I ‘Apply then Next style’ in Applescript.

Here is the part of the code that pulls the text in and applies my paragraph style. It all works fine but I need it to Apply then next.

Many thanks for any help.

tell myDocument
		set myTextFrame to make text frame of page 1 of myDocument with properties {stroke color:"None", fill color:"None"}
		--Set the bounds of the text frame.
		set geometric bounds of myTextFrame to {0, 0, 170, 160}
		--Enter text in the text frame.
		set contents of myTextFrame to ndstring1
		set applied paragraph style of text of myTextFrame to "Notable Date"
		set geometric bounds of myTextFrame to {54.25, 6, 144.307, 60}
end tell

Hi. I’m not sure if you’re actually expecting nested style behavior, which may affect immediate visual changes. If a paragraph style is defined with another style as its next, you need to add something after the target to assume the second style’s properties.

Hi Marc. Thank you for your reply.
Everything works exactly as I want it to except applying the ‘next’ style. It’s the ‘something after the target’ that I’m hoping someone can help me with. I’m just not finding the right syntax for it to apply the style and the next style. It always just applies the style without apllying the ‘next’ style too.

–Hi. If you mean that if you have 2 paragraph styles defined, eg, “testparastyle” and “testparastyle_next”, and you want the definition of “testparastyle” to specify “testparastyle_next” to be the Next Style in the definition of the “testparastyle” paragraph style, then you should be able to use something like:


tell application id "com.adobe.indesign"
	tell document 1		
		set next style of paragraph style "testparastyle" to paragraph style "testparastyle_next"
	end tell
end tell

– InD 2020; Mojave

Hmm, it appears that I was mistaken, as the AppleScript functionality for next style diverges from the real-world application in a rather non-intuitive and cumbersome way; you’ll need to edit an object style. It would likely be preferable to avoid the below method and simply assign the next paragraph style explicitly.

tell application "adobe indesign cs3"'s document 1
	set object style "[Basic Text Frame]"'s properties to {applied paragraph style:"A", apply next paragraph style:1}
	set text frame  1's parent text frame's paragraph 1's applied paragraph style to "A"
end tell

Many thanks for your reply kerflooey.

I have successfully defined all styles I need and have also defined what is the ‘next’ paragraph style.
When I go to InDesign everything is as it should be.

The issue I’m having is actually applying the paragraph style and next style through Applescript.
I can apply the paragraph style but the syntax for applying paragraph style and next style is what is eluding me.

Again, if I go to InDesign, select the text box and manually apply paragraph style and next style it all works exactly as it should. I just need to try and nail the syntax for doing that in the Applescript.

Many thanks for your reply Marc. Yes, it’s a slippery little rascal isn’t it!!
I’m trying to make your methodology work but I like your sentence

’ It would likely be preferable to avoid the below method and simply assign the next paragraph style explicitly.’

That’s exactly what I’m trying to do but, alas, with no success yet.

Again, many thanks for your help. You have put me on a new tract.

For clarification, what I meant by saying you should assign the next style explicitly is that you apply all paragraph styles explicitly, as needed, rather than using the semi-automated next style feature that requires an object style to work.

[format]set paragraph 1’s applied paragraph style to “A”
set paragraph 2’s applied paragraph style to “B”
set paragraph 3’s applied paragraph style to “C”
–etc[/format]

Okey Dokey, I solved it…

What I had (bearing in mind this is just a small part of a much larger script)…

tell myDocument
       set myTextFrame to make text frame of page 1 of myDocument with properties {stroke color:"None", fill color:"None"}
       --Set the temporary bounds of the text frame.
       set geometric bounds of myTextFrame to {0, 0, 170, 160}
       --Enter text in the text frame.
       set contents of myTextFrame to ndstring1
       set applied paragraph style of text of myTextFrame to "Notable Date"
       set geometric bounds of myTextFrame to {54.25, 6, 144.307, 60}
end tell

The paragraph style “Notable Date” is correctly defined (with its ‘next’ style) earlier in the script.

To make it apply the paragraph style and next style I did this:

tell myDocument
		set myTextFrame to make text frame of page 1 of myDocument with properties {stroke color:"None", fill color:"None"}
		--Set the temporary bounds of the text frame.
		set geometric bounds of myTextFrame to {0, 0, 170, 160}
		--Enter text in the text frame.
		set contents of myTextFrame to ndstring1
		
		set applied paragraph style of text of myTextFrame to "Notable Date"
		
		tell selection
			set applied paragraph style of text of myTextFrame to next style of myParagraphWeekday
		end tell
				
		set geometric bounds of myTextFrame to {54.25, 6, 144.307, 60}
end tell

It wouldn’t accept “Notable Date” in this line:

set applied paragraph style of text of myTextFrame to next style of myParagraphWeekday

So I had to use the variable name I used when defining the style, which is myParagraphWeekday.

So it finally works. Many thanks for all help given. It made me think along other lines.