14 Replies Latest reply: Feb 21, 2012 7:00 AM by [Jongware] RSS

    Random font script?

    cts_graphics Community Member
      Does anyone know of a script to assign random fonts to a bunch of text?

      Basically, I've got a slew of words which are going to go into a collage. Instead of manually changing the font, size, weight of each, I'd like each word to be changed automatically.

      I thought I'd seen one of these once, but I can't find head-nor-tail of it.

      Any help?
        • 1. Re: Random font script?
          Sandee Cohen Ban the Spam ACP/MVPs
          Don't know of a script, but you might have more fun with a ransom note font. There are several free ones hanging round the Web, but I like this one that is professionally done:

          • 2. Re: Random font script?
            [Jongware] MVP

            I wrote this ages ago: randomizing type features such as leading


            Shouldn't be too hard to add random fonts to the mix. Notice it randomizes characters. You can make it work on words by ... simply changing 'characters' into 'words'. Really.

            Oh, and change


            for (i=0; i<app.selection[0].length; i++)




            for (i=0; i<app.selection[0].paragraphs[0].words.length; i++)
            • 3. Re: Random font script?



              I have got the same problem.


              Did you find a solution to it ?


              Thank you.



              • 4. Re: Random font script?
                Peter Spier ACP/MVPs

                Here's a link to the new location of the original thread that jongware mentions: http://forums.adobe.com/message/1281781#1281781

                • 5. Re: Random font script?
                  Julien-caetla Community Member

                  THANKS A LOT !


                  You're a life saver.



                  • 6. Re: Random font script?
                    Peter Spier ACP/MVPs

                    This probably should get into the forum faqs, not that anyone would read it, but the way to find these old threads is to copy some bit of recognizable text from a post and paste it into the search field at the top of the page.


                    In this case I used the title of the old thread, "randomizing type features such as leading" and it popped right up.

                    • 7. Re: Random font script?
                      Julien-caetla Community Member

                      I keep this idea in my mind, i didn't think about it before.


                      Anyway, the script works, but it's not exactly what i had in mind.


                      I want to change the font of a text randomly, to get a "looking like" handwriting.


                      Is there a script function which will choose randomly between two or three fonts ?


                      Thans for all.



                      • 8. Re: Random font script?
                        Peter Spier ACP/MVPs

                        If you want the look of handwriting, why not use a font that looks like handwriting instead of playing mix-or-match.


                        • 9. Re: Random font script?
                          Julien-caetla Community Member

                          Because i'm working on some comics made by an artist.


                          In order to keep the creative work he made on his comics, i want to keep the feeling for the french translation of the book.


                          I am searching around for some javascript help for indesign, but it ain't easy.


                          If you got an idea, i'll be glad to ear it.



                          • 10. Re: Random font script?
                            Peter Spier ACP/MVPs

                            I'd still look for a handwriting-style font -- there were hundreds of them on that link -- that mimics the look of the original text.


                            But if you insist on randomizing fonts, you'll need to build a loop that works though character by character and generates a random number from 1 to whatever the number of fonts you want to choose from happens to be, then uses a switch to assign a font based on that number. I'm not a scripter, but jongware's script is a good starting point, and I'd guess that the font would be assigned with a line that looks something like app.selection[0].characters[i].font =



                            • 11. Re: Random font script?
                              CH design

                              did anyone come up with a finished solution?  I've got about exactly the same situation as the OP, and have been working with what I've found here, but really am a novice when it comes to scripting, so not sure I'm going to be able to pull off what I need.  Got about 800 names to put into a collage, and want to randomly assign fonts (from a set of just three or four), or at least font sizes and color (again, from a set of certain sizes and colors).  The names are two words each - first and last name - and these pairs need to match of course.


                              Any help would be greatly appreciated.



                              • 12. Re: Random font script?
                                [Jongware] MVP

                                Colin, you are a bit sketchy about what you have now ... Down here below is a Javascript that assumes you have a selection of text frames (one or more), each of which may contain one or more paragraphs. The script assigns a random font and swatch from a list to each separate paragraph. It doesn't attempt to select "pairs to match", it just uses each separate paragraph.


                                Before running the script, you must fill in the list of fonts and swatches to use. There is one peculiarity in scripting required: the font name and style MUST be separated from each other with a tab, NOT a space -- that is the special code '\t' in Javascript. (You can also type a tab but this way it's more clear what's happening). See the script for examples ("Impact" happens to have no particular style, so there I don't need a tab). No worries, the script will tell you if something is wrong.


                                Did I mention you can add as much fonts and swatches to choose from as you want? You can -- just continue the numbering (Be Friendly to your computer and don't skip numbers either).


                                Here is how it looks: I selected two text frames and ran my script. Then I ran it again on the same selection. Then I ran it again, just for good measures! Total randomness ensured.



                                And here is the Javascript (make sure to save as "randomcolor.jsx" or it won't work):


                                // Check selection
                                if (app.documents.length == 0 ||
                                 app.selection.length == 0)
                                 alert ('Please make sure to have some text frames selected first!')
                                var font = [];
                                var swatch = [];
                                font[0] = "Times New Roman\tRegular";
                                font[1] = "Myriad Pro\tSemibold";
                                font[2] = "Impact";
                                // font[3] = "etc. etc."
                                swatch[0] = "Red";
                                swatch[1] = "C=100 M=0 Y=100 K=0";
                                swatch[2] = "C=36 M=100 Y=26 K=0";
                                // swatch[3] = "etc. etc."
                                // Check fonts
                                for (i=0; i<font.length; i++)
                                 try {
                                  x = app.fonts.item(font[i]).fullName;
                                 } catch (_)
                                  alert ('The font name "'+font[i]+'" cannot be found -- please check spelling etc.');
                                // Check swatches
                                for (i=0; i<swatch.length; i++)
                                 try {
                                  x = app.activeDocument.swatches.item(swatch[i]).name;
                                 } catch (_)
                                  alert ('The swatch name "'+swatch[i]+'" cannot be found -- please check spelling etc.');
                                // Apply random colors and fonts!
                                for (sel=0; sel<app.selection.length; sel++)
                                 // Is this a text frame? (It better be!)
                                 if (app.selection[sel] instanceof TextFrame)
                                  // Ah right. Go over each of its text lines ..
                                  for (par=0; par<app.selection[sel].paragraphs.length; par++)
                                   // .. and apply random font and swatch
                                   app.selection[sel].paragraphs[par].appliedFont = font[Math.floor(Math.random()*font.length)];
                                   app.selection[sel].paragraphs[par].fillColor = swatch[Math.floor(Math.random()*swatch.length)];
                                • 13. Re: Random font script?
                                  CH design Community Member

                                  Your script here worked perfectly!  Thanks so much.  I entered the fonts and swatch colors I was using in my design, and then I added a little bit to the script so that it would randomize font sizes as well (the script chooses from among a certain set of point sizes I wanted); you can see what I added in these sections of the script here:


                                  var font = [];

                                  var swatch = [];

                                  var pointSize = [];

                                  font[0] = "Helvetica\tExtra Compressed";

                                  font[1] = "Minion Pro\tBold Cond";

                                  font[2] = "Trajan Pro\tBold";

                                  font[3] = "Minion Pro\tBold Cond Italic";

                                  // font[3] = "etc. etc."


                                  swatch[0] = "light brown";

                                  swatch[1] = "60p light brown";

                                  swatch[2] = "30p light brown";

                                  swatch[3] = "50p orange";

                                  swatch[4] = "25p orange";

                                  // swatch[3] = "etc. etc."


                                  pointSize[0] = "22.5";

                                  pointSize[1] = "15";

                                  pointSize[2] = "10";


                                  And then one more line at the very end:


                                  app.selection[sel].paragraphs[par].pointSize = pointSize[Math.floor(Math.random()*pointSize.length)];

                                  • 14. Re: Random font script?
                                    [Jongware] MVP

                                    Nice addition!


                                    Yeah that's how I learned to script as well: start with a working script, modify, then modify some more ... until you break something