CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Script to spell out state names not working in CC
- This topic has 6 replies, 3 voices, and was last updated 8 years, 12 months ago by
Cindy Kelley.
-
AuthorPosts
-
-
July 24, 2016 at 10:59 am #86879
Cindy Kelley
ParticipantHi 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;
} -
July 24, 2016 at 11:14 am #86880
Ari Singer
MemberDoes 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
-
July 25, 2016 at 3:38 am #86887
Cindy Kelley
ParticipantHi 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
-
July 25, 2016 at 7:48 am #86889
Matt Isaac
ParticipantThe 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; }
-
July 25, 2016 at 8:04 am #86892
Matt Isaac
ParticipantAfter 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
-
-
July 25, 2016 at 8:04 am #86894
Ari Singer
MemberThe 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; }
-
July 28, 2016 at 7:16 am #86964
Cindy Kelley
ParticipantHI gang,
This works GREAT! It is going to save me a lot of time.
Thanks!
…and this another reason I love indesignsecrets.com. :)
Cindy
-
-
AuthorPosts
- You must be logged in to reply to this topic.
