You must be logged in to post Login

Search Forums:


 






Spell out state abbreviations

UserPost

4:11 pm
December 3, 2011


tabaholic

Member

posts 24

Is there are script that does this? 


thanks for any info

5:16 pm
December 3, 2011


Jongware

Member

posts 764

Post edited 5:17 pm – December 3, 2011 by Jongware


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 = "\\b"+abbrevs[a][1]+"\\b";
app.changeGrepPreferences.changeTo = abbrevs[a][0];
app.activeDocument.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
}


6:43 pm
December 3, 2011


tabaholic

Member

posts 24

As always, you are my hero!

4:54 am
December 4, 2011


Jongware

Member

posts 764

Oh blushes.

Did you notice it comes with a cool "Undo" option?

12:14 pm
December 8, 2011


timruah

Community Member

posts 9

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

12:19 pm
December 8, 2011


David Blatner

Admin

posts 823

You can download this script here, for your convenience:

http://indesignsecrets.com/dow…..ations.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: http://indesignsecrets.com/how…..design.php

Hope that helps!

co-host, InDesignSecrets.com

12:57 pm
December 8, 2011


timruah

Community Member

posts 9

Definitely, thanks.

9:29 am
December 9, 2011


Anne-Marie

Admin

posts 147

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!  


http://www.lynda.com/InDesign-…..324-2.html


8:27 am
December 27, 2011


FrederickYocum

Akron, Pa. USA

Member

posts 26

Post edited 9:12 am – December 27, 2011 by FrederickYocum
Post edited 12:40 pm – December 27, 2011 by FrederickYocum


@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.

11:01 am
December 27, 2011


Jongware

Member

posts 764

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

1:03 pm
December 27, 2011


FrederickYocum

Akron, Pa. USA

Member

posts 26

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"]

3:28 pm
December 27, 2011


Jongware

Member

posts 764

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.

7:02 pm
December 27, 2011


FrederickYocum

Akron, Pa. USA

Member

posts 26

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!