9 Replies Latest reply on May 19, 2008 1:54 AM by Peter Kahrel

    [CS3][JS] find/change quotation marks to typographer quotes

      my document contains a lot of quotation marks but they are not typographic (the opening one and the closing one are similar (") i want them to be typographic. I tried this script and it doesn't work.

      var myDoc = app.activeDocument;
      
      app.findGlyphPreferences = NothingEnum.nothing;
      app.changeGlyphPreferences = NothingEnum.nothing;
      app.findGlyphPreferences.appliedFont = app.fonts.item("Times New Roman  Regular");
      app.findGlyphPreferences.glyphID = 5;
      var myFoundItems = myDoc.findGlyph();
      app.changeGlyphPreferences.appliedFont = app.fonts.item("Times New Roman  Regular");

      var r=0;
      for(i=0;i<myFoundItems.length;i++){
        app.changeGlyphPreferences.glyphID = 179;
          myFoundItems(r).changeGlyph();
      app.changeGlyphPreferences.glyphID = 180;
          myFoundItems(r+1).changeGlyph();
          r+=2;
      }
        • 1. Re: [CS3][JS] find/change quotation marks to typographer quotes
          Peter Kahrel Adobe Community Professional & MVP
          I think it's always tricky to use Glyph IDs as they can change from font to font. I would use something like this:

          myDoc = app.activeDocument;
          
          app.findTextPreferences = null;
          app.findTextPreferences.appliedFont = app.fonts.item("Times New Roman Regular");
          app.findTextPreferences.findWhat = '"'
          var myFoundItems = myDoc.findText();
          for(i=0;i<myFoundItems.length-1;i=i+2)
             {
             myFoundItems[i].contents = '\u201C';
             myFoundItems[i+1].contents = '\u201D';
             }


          Peter
          • 2. Re: [CS3][JS] find/change quotation marks to typographer quotes
            Martin Fischer Level 2
            Hi Peter,

            your solution is pretty good while the pairs of quotes are complete and you only use one sort of typographer quotes.

            But what if once the final quote is missing?
            Or if you want to use different language sensitive quotes for a document with multilingual text?

            Another approach is to take use of the execution of typographer quotes of InDesign itself.
            First you will have to activate typographer quotes:


            app.activeDocument.textPreferences.typographersQuotes = true;


            If you now change " with " you will get ".
            That's not what you have been looking for. ;-)

            You first have to make all non-typographical quotes to one specific typographical quote (right or wrong) or a placeholder. And than you have to change the specific typographical quotes to the non-typographical quotes (sic!). After that you will find your language-sensitive quotes.

            Here is an example.

            var myDoc = app.activeDocument;
            var myRange = (app.selection.length == 1 )
            ? app.selection[0]
            : myDoc;

            myDoc.textPreferences.typographersQuotes = true;

            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.appliedFont = myDoc.paragraphStyles[1].appliedFont.fullName;

            theChangeGrep ( '\[\\x{0027}\\x{2019}\\x{201A}\\x{2039}\\x{203A}\]', '\\x{2018}' );
            theChangeGrep ( '\[\\x{0022}\\x{201D}\\x{201E}\\x{00AB}\\x{00BB}\]', '\\x{201C}' );

            theChangeGrep ( '\\x{2018}', '\\x{0027}' );
            theChangeGrep ( '\\x{201C}', '\\x{0022}' );

            function theChangeGrep ( f, c)
            {
            app.findGrepPreferences.findWhat = f;
            app.changeGrepPreferences.changeTo = c;
            myRange.changeGrep();
            }

            It takes some more search executions, that's true.
            But it's language sensitive! ;-)

            After all, apostrophes () will disturb the changing also in this approach, because they are not recognized as apostrophes but as single typographical quotes.
            To prevent from this I am still looking for a solution.

            Martin
            • 3. Re: [CS3][JS] find/change quotation marks to typographer quotes
              Level 1
              Thanks Peter your scrip works fine.
              Martin, yours is not working for me, it seems that there is no such property called "fullName", and even if I change to "Times New Roman Regular" it replaces the quotation marks with strange characters (<< and >>)
              • 4. Re: [CS3][JS] find/change quotation marks to typographer quotes
                Martin Fischer Level 2
                Elic,

                first depends on the font you have defined in your first paragraph style (normal paragraph style). But you may be right that this will not work with every font (it's a q&d solution).

                Second depends on the settings for single and double quotes of the used language(s) - for it's language sensitive.
                Did you control them in the properties/dictionary ...?

                Martin
                • 5. Re: [CS3][JS] find/change quotation marks to typographer quotes
                  Peter Kahrel Adobe Community Professional & MVP
                  Martin,

                  You're quite right, that script works well only when the quotes are balanced. I put it like that as a working alternative to elic elico's approach.

                  >You first have to make all non-typographical quotes to one specific typographical quote (right or wrong) or a placeholder. And than you have to change the specific typographical quotes to the non-typographical quotes (sic!).

                  Aha! I didn't know that. Very useful, thanks. Makes life a lot easier. In your grep replacements you could use the quote wildcards, could you not? In grep, " finds any double quote, ' any single quote. So could you not say theChangeGrep ( '"', '\\x{2018}' ); with the same result?

                  As to apostrophes, maybe you could define them as "single quotes preceded and followed by a letter", which in greppian would be >[\u\l]'[\u\l]

                  This doesn't catch certain apostrophes in English, such as possessive plurals ("the programmers' plight"). For French and German it might wotk, though.

                  Peter
                  • 6. Re: [CS3][JS] find/change quotation marks to typographer quotes
                    Martin Fischer Level 2
                    Peter,

                    > So could you not say theChangeGrep ( '"', '\\x{2018}' ); with the same result?

                    Pretty good!
                    That works very well.
                    I did have too much respect for french quotes, but they also can be found while looking for ".
                    Thanks.

                    > This doesn't catch certain apostrophes in English, such as possessive plurals ("the programmers' plight"). For French and German it might wotk, though.

                    In German the apostrophe for the rarely used genitive case also stands at the end of a word: Klaus Buch.
                    Another case is the substitution of a character at the end of a word: Freud instead of Freude.

                    Martin
                    • 7. Re: [CS3][JS] find/change quotation marks to typographer quotes
                      Peter Kahrel Adobe Community Professional & MVP
                      >Another case is the substitution of a character at the end of a word: Freud instead of Freude.

                      Ah -- yes, in English you have those, too, such as grabbin'. And at the beginning of words, like 'phone and 'ere. And in contractions, like they're and can't. It's a 'opeless freekin' mess.

                      Peter
                      • 8. Re: [CS3][JS] find/change quotation marks to typographer quotes
                        Level 1
                        Indeed it is (a 'opeless freekin' mess). I wrote a script to tackle this task a couple of years back that exported text style ranges to tagged text and placed that back into InDesign, letting its typographer's quote setting managing the "smartening" of the quotes, but it gets things like 86 wrong.

                        Dave
                        • 9. Re: [CS3][JS] find/change quotation marks to typographer quotes
                          Peter Kahrel Adobe Community Professional & MVP
                          The 'opeless-type apostrophes can be found using this grep: ~]\< (closing quote followed by beginning of word), and word-internal apostrophes (l'ennui, couldn't) are also found. The remaining problem is word-final apostrophes (*******'); I don't think it's possible to distinguish these from closing quotes.

                          Peter