Thursday, September 08, 2005


Script of the Day -- Changing Case Again

A member of the BlueWorld list asked for a script to change the case of text in a particular style to lowercase. Completely forgetting that Shane Stanley had posted an AppleScript to do this a few weeks ago, I embarked on converting one of my scripts that makes use of a simple user dialog to do the job. Like many scripts, the doing of the job is relatively easy, but giving the user a way to say what he wants to do is a little more challenging.

In this case, I decided to let the user pick a paragraph style and choose which of the four possible case changes he wants to apply. Once more, the script is wrapped in the selection handling framework. Then a dialog with two drop-down menus is presented to the user. Finally, the real work is done in the small loop just before the functions.
//DESCRIPTION: Converts text in designated parastyle to designated case

if ((app.documents.length != 0) && (app.selection.length != 0)) {
 myDoc = app.activeDocument;
 myStyles = myDoc.paragraphStyles;
 myStringList = myStyles.everyItem().name;
 myCaseList = ["Uppercase","Lowercase", "Title case", "Sentence case"];
 myCases = [ChangecaseMode.uppercase, ChangecaseMode.lowercase, ChangecaseMode.titlecase, ChangecaseMode.sentencecase];

 var myDialog = app.dialogs.add({name:"Case Changer"})
   with (dialogRows.add()) {
    with (dialogColumns.add()) {
     staticTexts.add({staticLabel:"Paragraph Style:"});
    with (dialogColumns.add()) {
     myStyle = dropdowns.add({stringList:myStringList,selectedIndex:0,minWidth:133});
   with (dialogRows.add()) {
    with (dialogColumns.add()) {
     staticTexts.add({staticLabel:"Change Case to:"});
    with (dialogColumns.add()) {
     myCase = dropdowns.add({stringList:myCaseList,selectedIndex:0,minWidth:133});
 var myResult =;
 if (myResult != true){
  // user clicked Cancel
  theStyle = myStyle.selectedIndex;
  theCase = myCase.selectedIndex;

  app.findPreferences = null;
  app.changePreferences = null;
  myFinds ='',false,false,undefined,{appliedParagraphStyle:myStyles[theStyle]});
  myLim = myFinds.length;
  for (var j=0; myLim > j; j++) {

} else {

// +++++++ Functions Start Here +++++++++++++++++++++++

function errorExit(message) {
 if (arguments.length > 0) {
  if (app.version != 3) { beep() } // CS2 includes beep() function.
 exit(); // CS exits with a beep; CS2 exits silently.
I'm thinking that a variation of this script that let you choose character styles instead (or even one that let you choose one or the other) might be equally useful. And, I should probably integrate the early Smart Title Case script rather than lumber the user with InDesign's built-in dumb title case.

Dave - that looks like a fairly useful script. I'm wondering: could it be adapted to search for a particular font style (eg, bold or italic) and replace that formatting with a corresponding character style (which could be used, in turn, to map that text to a tag)?

nice work!

I want a script to find the text which is in particular font style like "Italic" or "Regular" without considering the font family and after find that text it as to get tag for that content like File.
Can u please help me.

The first part of your request is probably covered here in the blog a hundred times -- although the exact syntax depends on which version of InDesign you're using. The second part seems to have lost some coherence in the ether because I haven't a clue what you mean.

Try visiting the Adobe User-to-User forums for more immediate help from a variety of people.

How can I apply this script when converting text that is ALL CAPS to sentence case, remembering to capitalize certain words (names of towns, people's names' etc.)?

You'd have to build an exception list. If you look at my Smart Title Case script, you'll see the sort of thing you need.
I'm not sure what to put in an exception list as I want to convert ALL CAPS text to sentence case, with the exception of a few words.

If I am converting it to sentence case instead of title case, then every word would have to be ignored except the ones I want to capitalize (and the first letter of the sentence). Does that make sense?

How can I change the script to convert it to sentnece case (not title case) and then enter my exceptions?

Thanks so much. Either way the script is very useful for converting titles.

If you haven't much experience with script, that might be daunting. But basically, you need to modify the script so that any words after the first are left as lowercase. The exception logic should still work.

Mind you I'm typing this from memory. It's been a while since I did anything with this script.

Hi Dave!

I'm using CS3 (InDesign 5.02) and have placed the script in the proper folder, but when I run it, after making my choices, nothing happens once the dialog closes. I've tried it with a variety of styles in the document, but it appears to have no effect. Makes me think there's something not happening elsewhere, causing the script to fail. (Does it just not work in CS3?)

Any ideas how I can troubleshoot this further, or provide you with more helpful info to identify the issue?
The script uses the CS2 search methods, so to make this work under CS3 (or CS4) without modification, you'll need to store it in a folder named:

Version 4.0 Scripts

Hi! Thank you for a fantastic script! Hugs from Norway!
i'd love to use this, but am using CS3 and it does not seem to work (i placed it in a folder named Version 4.0 Scripts s you suggested)
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?