Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to spell out state names not working in CC

Return to Member Forum

  • Author
    Posts
    • #86879
      Cindy Kelley
      Participant

      Hi there,

      This script worked fine for CS6 but I can’t get it to work for CC. Any ideas why?

      Thanks,
      Cindy

      //DESCRIPTION:Expand US State Abbreviations
      if (app.version < ‘6’)
      doReplace();
      else
      app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Expand State Abbreviations”);
      function doReplace ()
      {
      var a;
      var abbrevs = [
      [ “Alabama”, “Ala.” ],
      [ “Arizona”, “Ariz.” ],
      [ “Arkansas”, “Ark.” ],
      [ “California”, “Calif.” ],
      [ “Colorado”, “Colo.” ],
      [ “Connecticut”, “Conn.” ],
      [ “Delaware”, “Del.” ],
      [ “District Of Columbia”, “D.C.” ],
      [ “Florida”, “Fla.” ],
      [ “Georgia”, “Ga.” ],
      [ “Illinois”, “Ill.” ],
      [ “Indiana”, “Ind.” ],
      [ “Kansas”, “Kan.” ],
      [ “Kentucky”, “Ky.” ],
      [ “Louisiana”, “La.” ],
      [ “Maryland”, “Md.” ],
      [ “Massachusetts”, “Mass.” ],
      [ “Michigan”, “Mich.” ],
      [ “Minnesota”, “Minn.” ],
      [ “Mississippi”, “Miss.” ],
      [ “Missouri”, “Mo.” ],
      [ “Montana”, “Mont.” ],
      [ “Nebraska”, “Neb.” ],
      [ “Nevada”, “Nev.” ],
      [ “New Hampshire”, “N.H.” ],
      [ “New Jersey”, “N.J.” ],
      [ “New Mexico”, “N.M.” ],
      [ “New York”, “N.Y.” ],
      [ “North Carolina”, “N.C.” ],
      [ “North Dakota”, “N.D.” ],
      [ “Oklahoma”, “Okla.” ],
      [ “Oregon”, “Ore.” ],
      [ “Pennsylvania”, “Pa.” ],
      [ “Rhode Island”, “R.I.” ],
      [ “South Carolina”, “S.C.” ],
      [ “South Dakota”, “S.D.” ],
      [ “Tennessee”, “Tenn.” ],
      [ “Vermont”, “Vt.” ],
      [ “Virginia”, “Va.” ],
      [ “Wash.”, “Washington” ],
      [ “West Virginia”, “W.Va.” ],
      [ “Wisconsin”, “Wis.” ],
      [ “Wyoming”, “Wyo.” ] ];

      app.findGrepPreferences = app.changeGrepPreferences = null;
      for (a in abbrevs)
      {
      app.findGrepPreferences.findWhat = “b”+abbrevs[a][1]+”b”;
      app.changeGrepPreferences.changeTo = abbrevs[a][0];
      app.findGrepPreferences.appliedParagraphStyle = “scholarship winner”;
      app.activeDocument.changeGrep();
      }
      app.findGrepPreferences = app.changeGrepPreferences = null;
      }

    • #86880
      Ari Singer
      Member

      Does your document have the “scholarship winner” paragraph style applied?

      Try this:

      //DESCRIPTION:Expand US State Abbreviations
      
      app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");
      function doReplace ()
      {
      var a;
      var abbrevs = [
      [ "Alabama", "Ala." ],
      [ "Arizona", "Ariz." ],
      [ "Arkansas", "Ark." ],
      [ "California", "Calif." ],
      [ "Colorado", "Colo." ],
      [ "Connecticut", "Conn." ],
      [ "Delaware", "Del." ],
      [ "District Of Columbia", "D.C." ],
      [ "Florida", "Fla." ],
      [ "Georgia", "Ga." ],
      [ "Illinois", "Ill." ],
      [ "Indiana", "Ind." ],
      [ "Kansas", "Kan." ],
      [ "Kentucky", "Ky." ],
      [ "Louisiana", "La." ],
      [ "Maryland", "Md." ],
      [ "Massachusetts", "Mass." ],
      [ "Michigan", "Mich." ],
      [ "Minnesota", "Minn." ],
      [ "Mississippi", "Miss." ],
      [ "Missouri", "Mo." ],
      [ "Montana", "Mont." ],
      [ "Nebraska", "Neb." ],
      [ "Nevada", "Nev." ],
      [ "New Hampshire", "N.H." ],
      [ "New Jersey", "N.J." ],
      [ "New Mexico", "N.M." ],
      [ "New York", "N.Y." ],
      [ "North Carolina", "N.C." ],
      [ "North Dakota", "N.D." ],
      [ "Oklahoma", "Okla." ],
      [ "Oregon", "Ore." ],
      [ "Pennsylvania", "Pa." ],
      [ "Rhode Island", "R.I." ],
      [ "South Carolina", "S.C." ],
      [ "South Dakota", "S.D." ],
      [ "Tennessee", "Tenn." ],
      [ "Vermont", "Vt." ],
      [ "Virginia", "Va." ],
      [ "Wash.", "Washington" ],
      [ "West Virginia", "W.Va." ],
      [ "Wisconsin", "Wis." ],
      [ "Wyoming", "Wyo." ] ];
      
      app.findGrepPreferences = app.changeGrepPreferences = null;
      for (a in abbrevs)
      {
      	app.findGrepPreferences.findWhat = "b" + abbrevs[a][1] + "b";
      	app.changeGrepPreferences.changeTo = abbrevs[a][0];
      	app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("scholarship winner");
      	app.activeDocument.changeGrep();
      	}
      app.findGrepPreferences = app.changeGrepPreferences = null;
      }
      

      If it does still not work, please spell me out the error that pops up.

      -Ari

    • #86887
      Cindy Kelley
      Participant

      Hi there,

      Yes, I do have a paragraph style of “scholarship winner”.

      This script still doesn’t work. It appears to do nothing so I don’t get an error code of any sort.

      Thank you for taking your time to look at this Ari. :)

      Cindy

    • #86889
      Matt Isaac
      Participant

      The problem was in the findGrepPreferences with the word boundary. Removing the boundaries worked for me. Also the single quotes around the 6 were removed (with the quotes it would not use the undo feature.)
      This code should work

      
      //DESCRIPTION:Expand US State Abbreviations
      if (app.version < 6)
      doReplace();
      else
      app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");
      function doReplace ()
      {
      var a;
      var abbrevs = [
      [ "Alabama", "Ala." ],
      [ "Arizona", "Ariz." ],
      [ "Arkansas", "Ark." ],
      [ "California", "Calif." ],
      [ "Colorado", "Colo." ],
      [ "Connecticut", "Conn." ],
      [ "Delaware", "Del." ],
      [ "District Of Columbia", "D.C." ],
      [ "Florida", "Fla." ],
      [ "Georgia", "Ga." ],
      [ "Illinois", "Ill." ],
      [ "Indiana", "Ind." ],
      [ "Kansas", "Kan." ],
      [ "Kentucky", "Ky." ],
      [ "Louisiana", "La." ],
      [ "Maryland", "Md." ],
      [ "Massachusetts", "Mass." ],
      [ "Michigan", "Mich." ],
      [ "Minnesota", "Minn." ],
      [ "Mississippi", "Miss." ],
      [ "Missouri", "Mo." ],
      [ "Montana", "Mont." ],
      [ "Nebraska", "Neb." ],
      [ "Nevada", "Nev." ],
      [ "New Hampshire", "N.H." ],
      [ "New Jersey", "N.J." ],
      [ "New Mexico", "N.M." ],
      [ "New York", "N.Y." ],
      [ "North Carolina", "N.C." ],
      [ "North Dakota", "N.D." ],
      [ "Oklahoma", "Okla." ],
      [ "Oregon", "Ore." ],
      [ "Pennsylvania", "Pa." ],
      [ "Rhode Island", "R.I." ],
      [ "South Carolina", "S.C." ],
      [ "South Dakota", "S.D." ],
      [ "Tennessee", "Tenn." ],
      [ "Vermont", "Vt." ],
      [ "Virginia", "Va." ],
      [ "Washington", "Wash." ],
      [ "West Virginia", "W.Va." ],
      [ "Wisconsin", "Wis." ],
      [ "Wyoming", "Wyo." ] ];
      app.findGrepPreferences = app.changeGrepPreferences = null;
      for (a in abbrevs)
      {
      app.findGrepPreferences.findWhat = abbrevs[a][1];
      app.changeGrepPreferences.changeTo = abbrevs[a][0];
      app.findGrepPreferences.appliedParagraphStyle = "scholarship winner";
      app.activeDocument.changeGrep();
      }
      app.findGrepPreferences = app.changeGrepPreferences = null;
      }
      
      • #86892
        Matt Isaac
        Participant

        After posting i realized that all of the periods need to be escaped in the abbreviations..

        
        //DESCRIPTION:Expand US State Abbreviations
        if (app.version < 6)
        doReplace();
        else
        app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");
        function doReplace ()
        {
        var a;
        var abbrevs = [
        [ "Alabama", "Ala." ],
        [ "Arizona", "Ariz." ],
        [ "Arkansas", "Ark." ],
        [ "California", "Calif." ],
        [ "Colorado", "Colo." ],
        [ "Connecticut", "Conn." ],
        [ "Delaware", "Del." ],
        [ "District Of Columbia", "D.C." ],
        [ "Florida", "Fla." ],
        [ "Georgia", "Ga." ],
        [ "Illinois", "Ill." ],
        [ "Indiana", "Ind." ],
        [ "Kansas", "Kan." ],
        [ "Kentucky", "Ky." ],
        [ "Louisiana", "La." ],
        [ "Maryland", "Md." ],
        [ "Massachusetts", "Mass." ],
        [ "Michigan", "Mich." ],
        [ "Minnesota", "Minn." ],
        [ "Mississippi", "Miss." ],
        [ "Missouri", "Mo." ],
        [ "Montana", "Mont." ],
        [ "Nebraska", "Neb." ],
        [ "Nevada", "Nev." ],
        [ "New Hampshire", "N.H." ],
        [ "New Jersey", "N.J." ],
        [ "New Mexico", "N.M." ],
        [ "New York", "N.Y." ],
        [ "North Carolina", "N.C." ],
        [ "North Dakota", "N.D." ],
        [ "Oklahoma", "Okla." ],
        [ "Oregon", "Ore." ],
        [ "Pennsylvania", "Pa." ],
        [ "Rhode Island", "R.I." ],
        [ "South Carolina", "S.C." ],
        [ "South Dakota", "S.D." ],
        [ "Tennessee", "Tenn." ],
        [ "Vermont", "Vt." ],
        [ "Virginia", "Va." ],
        [ "Washington", "Wash." ],
        [ "West Virginia", "W.Va." ],
        [ "Wisconsin", "Wis." ],
        [ "Wyoming", "Wyo." ] ];
        app.findGrepPreferences = app.changeGrepPreferences = null;
        for (a in abbrevs)
        {
        app.findGrepPreferences.findWhat = abbrevs[a][1];
        app.changeGrepPreferences.changeTo = abbrevs[a][0];
        app.findGrepPreferences.appliedParagraphStyle = "scholarship winner";
        app.activeDocument.changeGrep();
        }
        app.findGrepPreferences = app.changeGrepPreferences = null;
        }
        

        This code will be the one you should use unless Ari comes up with something better. =P

    • #86894
      Ari Singer
      Member

      The issue seemed to be the Word Boundary after a period (.). So I change it to a Negative Lookahead ((?!\w)) and it worked.

      I also adjusted the GREP search string so that it would be more accurate, because in GREP the period . is a wildcard that stands for every letter, and is only a period if it’s preceded by a backslash. But in the script the period was never escaped out, so it would find “Fla.” but it would also find and change “Flag”! (Not good…).

      So now I added a regex at the end to fix that. (As well as fixing that Wash. entry…).

      //DESCRIPTION:Expand US State Abbreviations
      
      app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");
      function doReplace ()
      {
      var a;
      var abbrevs = [
      [ "Alabama", "Ala." ],
      [ "Arizona", "Ariz." ],
      [ "Arkansas", "Ark." ],
      [ "California", "Calif." ],
      [ "Colorado", "Colo." ],
      [ "Connecticut", "Conn." ],
      [ "Delaware", "Del." ],
      [ "District Of Columbia", "D.C." ],
      [ "Florida", "Fla." ],
      [ "Georgia", "Ga." ],
      [ "Illinois", "Ill." ],
      [ "Indiana", "Ind." ],
      [ "Kansas", "Kan." ],
      [ "Kentucky", "Ky." ],
      [ "Louisiana", "La." ],
      [ "Maryland", "Md." ],
      [ "Massachusetts", "Mass." ],
      [ "Michigan", "Mich." ],
      [ "Minnesota", "Minn." ],
      [ "Mississippi", "Miss." ],
      [ "Missouri", "Mo." ],
      [ "Montana", "Mont." ],
      [ "Nebraska", "Neb." ],
      [ "Nevada", "Nev." ],
      [ "New Hampshire", "N.H." ],
      [ "New Jersey", "N.J." ],
      [ "New Mexico", "N.M." ],
      [ "New York", "N.Y." ],
      [ "North Carolina", "N.C." ],
      [ "North Dakota", "N.D." ],
      [ "Oklahoma", "Okla." ],
      [ "Oregon", "Ore." ],
      [ "Pennsylvania", "Pa." ],
      [ "Rhode Island", "R.I." ],
      [ "South Carolina", "S.C." ],
      [ "South Dakota", "S.D." ],
      [ "Tennessee", "Tenn." ],
      [ "Vermont", "Vt." ],
      [ "Virginia", "Va." ],
      [ "Washington", "Wash." ],
      [ "West Virginia", "W.Va." ],
      [ "Wisconsin", "Wis." ],
      [ "Wyoming", "Wyo." ] ];
      
      app.findGrepPreferences = app.changeGrepPreferences = null;
      for (a in abbrevs)
      {
      	var myString = abbrevs[a][1].replace(/\./g, '.');
      	app.findGrepPreferences.findWhat = "b" + myString+ "(?!w)";
      	app.changeGrepPreferences.changeTo = abbrevs[a][0];
      	app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("scholarship winner");
      	app.activeDocument.changeGrep();
      	}
      app.findGrepPreferences = app.changeGrepPreferences = null;
      }
      
    • #86964
      Cindy Kelley
      Participant

      HI gang,

      This works GREAT! It is going to save me a lot of time.

      Thanks!

      …and this another reason I love indesignsecrets.com. :)

      Cindy

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
Forum Ads