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

Spell out state abbreviations

Return to Member Forum

  • Author
    Posts
    • #61216
      Cindy Kelley
      Participant

      Is there are script that does this?

      thanks for any info

    • #61217

      Hi Cindy!

      Well not that I know of but it's easy enough. Uh, for me it is, anyway.

      //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”, AL ], [ “Alaska”, AK ], [ “American Samoa”,
      AS ], [ “Arizona”, AZ ], [ “Arkansas”, AR ], [ “California”, CA
      ], [ “Colorado”, CO ], [ “Connecticut”, CT ], [ “Delaware”, DE ],
      [ “District Of Columbia”, DC ], [ “Federated States Of Micronesia”,
      FM ], [ “Florida”, FL ], [ “Georgia”, GA ], [ “Guam Gu”, GU ], [
      “Hawaii”, HI ], [ “Idaho”, ID ], [ “Illinois”, IL ], [ “Indiana”,
      IN ], [ “Iowa”, IA ], [ “Kansas”, KS ], [ “Kentucky”, KY ], [
      “Louisiana”, LA ], [ “Maine”, ME ], [ “Marshall Islands”, MH ], [
      “Maryland”, MD ], [ “Massachusetts”, MA ], [ “Michigan”, MI ], [
      “Minnesota”, MN ], [ “Mississippi”, MS ], [ “Missouri”, MO ], [
      “Montana”, MT ], [ “Nebraska”, NE ], [ “Nevada”, NV ], [ “New Hampshire”,
      NH ], [ “New Jersey”, NJ ], [ “New Mexico”, NM ], [
      “New York”, NY ], [ “North Carolina”, NC ], [ “North Dakota”, ND
      ], [ “Northern Mariana Islands”, MP ], [ “Ohio”, OH ], [ “Oklahoma”,
      OK ], [ “Oregon”, OR ], [ “Palau”, PW ], [ “Pennsylvania”, PA ],
      [ “Puerto Rico”, PR ], [ “Rhode Island”, RI ], [ “South Carolina”,
      SC ], [ “South Dakota”, SD ], [ “Tennessee”, TN ], [ “Texas”, TX
      ], [ “Utah”, UT ], [ “Vermont”, VT ], [ “Virgin Islands”, VI ], [
      “Virginia”, VA ], [ “Washington”, WA ], [ “West Virginia”, WV ], [
      “Wisconsin”, WI ], [ “Wyoming”, WY ] ];

      app.findGrepPreferences = app.changeGrepPreferences = null;

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

    • #61218
      Cindy Kelley
      Participant

      As always, you are my hero!

    • #61219

      Oh blushes.

      Did you notice it comes with a cool “Undo” option?

    • #61240
      timruah
      Member

      Question from someone who's very unlearned in the whole scripting thing… how do I download this script onto my Mac?

    • #61241
      David Blatner
      Keymaster

      You can download this script here, for your convenience:

      https://creativepro.com/downloads/forcedl/stateAbbreviations.jsx

      If your browser puts a .txt at the end, remove that (it should end .jsx)

      Put it in the Scripts Panel folder, which we describe here: https://creativepro.com/how-to-install-scripts-in-indesign.php

      Hope that helps!

    • #61242
      timruah
      Member

      Definitely, thanks.

    • #61243

      We show exactly “How to download a script someone wrote out in a forum post” in video #016, (“Running a Script”) in our short-and-sweet InDesignSecrets videocasts on Lynda.com!

      https://www.lynda.com/InDesign-CS5-tutorials/InDesign-Secrets/85324-2.html

    • #61309

      @Jongware

      Nice little script which I used on a set of business card templates that needed to go from full state names to abbreviations. I ran into an edge case however. Washington D.C. How to tell the difference?

      Since the script uses grep it might be possible to do a look ahead to check for the letters D.C. or District of Columbia, I don’t know if this can be accomplished using scripting. It might be possible to do a look ahead for the postal/zip code, in fact, this would be generally useful because using postal abbrevations are usually only relevant for the state name when it is in an address block. I simply did a normal find and replace and corrected the Washingtons by hand. In any case using the script was still much quicker than 52 find and replaces.

    • #61310

      Frederick, that's a cool reversal of the original script!

      You are correct, GREP can distinguish both Washingtons using a look ahead. Change the Find entry in the abbreviations array from

      [ “Washington”, WA ]

      to

      [ “Washington(?! D.C.)”, WA ]

      and the problem ought to be solved — you don't have to change anything else in the script. For your other suggestion,

      It might be possible to do a look ahead for the postal/zip code, in fact, this would be generally useful because using postal abbrevations are usually only relevant for the state name when it is in an address block.

      I need to see some examples of what your USPS codes look like. I don't see many of those over here in Holland :D

    • #61312

      Thanks Jongware

      American ZIP codes either contain five digits or, five digits hyphen then four additional digits. So then it would be?

      [“Washington(?= ddddd[ -]?)”, “WA”]

    • #61313

      Yes, that ought to work (the forum software ate your backslahes before each 'd' — to have them appear in tour post, you need to enter 2 of 'em).

      Rather than adjusting every separate string in the Find What array, you could paste this at the end of the constrcuted findWhat string.

    • #61314

      Rather than adjusting every separate string in the Find What array, you could paste this at the end of the constructed findWhat string.

      Of course, brilliant!

    • #64930

      With the global update of the entire forum some links appear to be broken. The correct download link to the script is

      https://creativepro.com/downloads/forcedl/stateAbbreviations.jsx

    • #64933
      David Blatner
      Keymaster

      Thanks, Jongware. I have fixed the original links in this forum thread. As it turns out, the full links are usually there, but they’re hidden in the HTML as an href. But the “visible link” is wrong. So it’s easy to fix when I find them (but it’s hard to find them).

    • #79052

      I know this is a old thread. Can this be reversed? I have the states spelled out and want to use the postal code abbreviations. I changed the order inside the brackets but get an Invalid value for set property ‘changeTo’ message when I run it.

    • #99925
      Ed Maceyko
      Member

      I know this is an old thread but I use this script and find it very helpful but we often have college degree abbreviations in our text that are the same as some state abbreviations. So the doctoral MD gets changes to Maryland and Masters of Science MS is changed to Mississippi. The degrees have commas after them and the state abbreviation do not–could that comma be used in the script to differentiate?

    • #99965
      Peter Kahrel
      Participant

      Try changing this line:

      app.findGrepPreferences.findWhat = “”+abbrevs[a][1]+””;

      to

      app.findGrepPreferences.findWhat = “”+abbrevs[a][1]+”(?!,)”;

      which translates as ‘Find tw-letter abbreviations not followed by a comma’. It may still find things you’re not after, so click ‘Find next’ a few times to see what you get.

      P.

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