Home > HOT Posts!, InDesign Scripts > Search paragraph style names

Search paragraph style names

Well, here is something very handy. With this script you can search through your paragraph style names.

var myDoc = app.activeDocument;
var myStyles = myDoc.allParagraphStyles;
var foundStyles = Array();
var searchString = String();
searchString = 'He';
var tempName = String();
for(var i = 1; myStyles.length > i; i++){
   tempName = myStyles[i].name;
   if(tempName.substr (0, searchString.length) == searchString){
       foundStyles.push (tempName);
   }
}

alert(foundStyles);

All you have to do is to change searchString. Script is matching beginning of style name with searchString and if the match is found, whole style name is pushed into Array. Keep in mind that search IS case sensitive! So at the end, you get an Array with style names that passed matching. If you want to search whole style name instead of searching from beginning alter line 9 like this:

if(tempName.indexOf (searchString) != -1){

[UPDATE]

Or, if you want to do non case sensitive search with searching whole style name try this:

var myDoc = app.activeDocument;
var myStyles = myDoc.allParagraphStyles;
var foundStyles = Array();
var searchString = String();
searchString = 'ody';
var tempName = String();
for(var i = 1; myStyles.length > i; i++){
   tempName = myStyles[i].name;
   tempName1 = tempName.toLowerCase();
   if(tempName1.indexOf (searchString.toLowerCase()) != -1){
       foundStyles.push (tempName);
   }
}

alert(foundStyles);

That’s it, nothing else to say :)

About these ads
  1. Uwe Laubender
    July 27, 2010 at 11:02 | #1

    Hi, Tomaxxi!
    That script would not find paragraph styles inside style groups. To get them one would use:
    var myStyles = myDoc.allParagraphStyles;

  1. July 24, 2010 at 20:13 | #1
  2. June 1, 2011 at 14:30 | #2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 34 other followers

%d bloggers like this: