Skip to main content
Inspiring
October 21, 2009
Question

Apply paragraph style with next style

  • October 21, 2009
  • 2 replies
  • 4875 views

Hi. I haven't been in this forum for a long time, mostly because I've wanted to concentrate on AppleScript and JavaScript seems so preponderant here. Before stating my current question I'll say that some interesting AS discussions have been happening on the Lasso InDesign list, to which I especially invite any AppleScripters: http://www.listsearch.com/InDesign/. I'm tagging my scripting messages there with "AS:" or "AS/JS:" so that people who aren't interested in scripting can filter them out, and I suppose people from here might want to filter out every message that *wasn't* tagged in this way.

Apparently nobody on the Lasso list can help me with this question. Michael Brady has taught those of us there who weren't aware of it that with a multiparagraph selection you can control/right-click on a paragraph style, choose Apply "[name of style]" with Next Style, and then next styles are applied throughout the selection. This is great, but I want to avoid having to mouse to the paragraph styles panel, control-click and drag down to the menu selection. I figure this kind of style application should be scriptable, and "with next style" compiles in AppleScript... but without any apparent effect that I've noticed, and only [clearing overrides boolean] is shown in the scripting dictionary.

Can this desired type of style application be scripted? If so, how? I assume I'll need a separate script for every first-paragraph style.

Thanks.

This topic has been closed for replies.

2 replies

Harbs.
Legend
October 21, 2009

Yes.

http://in-tools.com/wordpress/indesign/plugins/formatting-tools-version-104-released

Harbs

Roy McCoyAuthor
Inspiring
October 22, 2009

Yes.

>

http://in-tools.com/wordpress/indesign/plugins/formatting-tools-version-104-released

Alas, my 30-day-demo has expired, and though Formatting Tools is still

in my Plug-Ins folder, InDesign doesn't recognize it. I used it only a

couple of times during the month and for some reason (inertia?

laziness? stupidity? too busy doing it the old way?) didn't get

adequately into it. One of the things that likely didn't work in its

favor was that though sophisticated scripting was evidently involved,

its application was still manual. I'm almost done with my current 108-

article book and thus with its main job script (which has been

invaluably handy), but what I would now want to do, having acquired

experience with Next Style throughout the job, would be to incorporate

calls to Formatting Tools, or work its routines into my own script, so

that Next Style would be applied to a defined sequence of next-style

paragraph styles in the book. This would eliminate the need to invoke

Formatting Tools, or anything other than the main job script, manually.

Thanks,

Roy

AhmetSamsa
Known Participant
May 30, 2017

Hello Roy,

I´m a beginner in scripting. The code I posted before works fine to me but it´s surely not a good solution for any purposes.

This one should be a little bit more flexible. In my test I had a title with next Style = subtitle and for the subtitle next Style = body and for body is the next Style = same Style

var style_name = "h1"

var doc = app.documents[0];
var first_pstyle = doc.paragraphStyles.item(style_name);
var cur_sel = app.selection[0].paragraphs;

cur_sel[0].appliedParagraphStyle = first_pstyle;

if (cur_sel.length > 1) 
     {
     for (n = 1; n < cur_sel.length; n++)
          {
          cur_sel.appliedParagraphStyle = cur_sel[n-1].appliedParagraphStyle.nextStyle;
          }
     }

cheers rübi


Hi Kai. I know this an old topic but script is still working. But its not working for styles in a group. Could you add an option for styles in group too?

Kai Rübsamen
Participating Frequently
October 21, 2009

Hi, I´m sorry that I´ve no code in Applescript for you, but in JS you can try something like this:

p_styles = app.documents[0].paragraphStyles;
cur_sel = app.selection[0].paragraphs;

cur_sel.item(0).applyParagraphStyle (p_styles.item ("title"), true);
cur_sel.item(1).applyParagraphStyle (p_styles.item ("title").nextStyle, true)

ruebi

Roy McCoyAuthor
Inspiring
October 22, 2009

Thanks Kai. This doesn't do what I want - which is work on any number

of paragraphs, not just 0 and 1 as here, or 0 and 1 and 2 if I add

cur_sel.item(2) - but it does finally suggest to me how "with next

style" actually works, which is applying not the specified style

itself but its assigned next after style.