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

Tip on why this script of AP style states to full names doesn't work?

Return to Forums

  • Author
    Posts
    • #1192003
      Cindy Kelley
      Participant

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

    • #14323901

      Can you please expand on “it does not work”? It’s like taking your car to a garage and telling the mechanic “it does not work”. They’ll be pressing for details too. (“I meant the windshield wipers don’t work”, for example.)

      It’s a JavaScript and so you should be saving it into your Script Folder with a .jsx file extension. Also, are you using Adobe’s own ESTK editor to enter it? At times, people use Word or TextEdit to edit their scripts (which is their good right; both are indeed good editors, and why not use it if you are familiar with how it works?) but they forget that a plain “Save” command from these will save the text in each respective’s own internal file format, and InDesign can’t read these. (Which it actaully can – Word saves as a file type of .docx and TextEdit saves as .rtf, aand you can import both of these into InDesign. But scripts are not imported,) The ESTK editor saves in the right file format; if you use something else then make sure you save your script as “plain text”.

      Also pay particular attention to things such as en-dashes and quotes. Sometimes the forum software (or, indeed, “smart” text editors such as Word) replaces a double minus as in i--; (a faster way of typing i = i - 1;) with a single en-dash, and changes straight single and double quotes to “typographically correct” curly open and close quotes. If your script has been saved correctly but it shows an error on a certain line, inspect that line for these special characters and correct them. For clarity: programming languages need straight quotes.*
      Using the ESTK editor has an advantage here: ‘text strings’ get colored differently than other code, and if you have the wrong kind of quote, you can see the string does not get colored correctly, or its color extends past where you would expect.

      * Because Historical Reasons. Ye Olde Keyboards did not contain correct quotes and used the same characters for open and closing, and also for feet and inches, and minutes and seconds. That “Ye Olde Keyboards” even harks back to the very first mechanical typewriters, although I think it’s excusable because one could not enter programs into a computer with pen and paper, it needed a keyboard. (As it happens, I am typing this on my iPad which does not have a keyboard. Oh how progress progresses. And I can type curly open en close quotes! But programming languages lag behind. And it’s also easier to use just a single character, rather than hunting for the correct one.)

    • #14323893
      Cindy Kelley
      Participant

      I ended up changing my text manually but will take a look at this script and your questions and suggestions when I get through this deadline. Thank you for all your thoughtful time.

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