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

Random font per character script

Return to Member Forum

  • Author
    Posts
    • #1219942
      Fons Dams
      Member

      Hi

      I am looking for a script that sets every character in a text out of one of the four fonts it defines and do this randomly.

      Can this (or a variation on this idea) be done with scripting in InDesign?

      Thnx
      Stijn

    • #14323376
      Brian Pifer
      Participant

      Sure. With the text in question selected:

      var chars = app.selection[0].characters;
      var fonts = [“Font1”, “Font2”, “Font3”, “Font4”];
      for (var i = 0; i < chars.length; i++) {
      var rando = Math.floor(Math.random() * Math.floor(4));
      chars[i].appliedFont = fonts[rando];
      }

    • #14323373
      Fons Dams
      Member

      Thanx Brian!

      I tried the script but got an error:

      JavaScript Error!
      Error Number: 8
      Error String: Syntax error
      Engine: main
      File (path to script)
      Line: 1
      Source: {\rtf1nsinsicpg1252\cocoartf1671\cocoasubrtf600
      Offending Text: \

      Any idea what went wrong?

    • #14323372
      Brian Pifer
      Participant

      Be sure you copied what I have above into a plain text editor such as Notepad, then save as a .jsx, not a word processing application like Word.

    • #14323371
      Fons Dams
      Member

      Hi Brian
      I did what you suggested, but still the same error :(
      I made a version with exactly the same text (copy/paste) as above and one with the Font1 etc replaced with actual font names installed on my system (Minion Pro.otf etc).
      Thanx for helping me out!!
      Stijn

    • #14323370

      You must be using TextEdit on a Mac. It is not possible that the suggested NotePad (the canonical plain text editor on Windows) would have shown that particular error. TextEdit assumes you want to add formatting to a text, and so it saves new files by default in the RTF (“rich text file”) format, but a script needs to be ASCII text only. That’s why it chokes on the very first formatting codes.

      Make sure that you set TextEdit to “Make Plain Text” before saving.

      Or, just use Adobe’s own ExtendScript Toolkit editor. It has the additional advantage that you can see syntax highlighting, so you’ll know it when a string is not properly defined.

      By the way: your font is not named “Minion Pro.otf” – look in your Font menu! Just use the font name. If you want to add a style as well, you can add it after a tab after the font name:

      var fonts = [ "Minion ProRegular", "Minion ProBold" ...
    • #14323366
      Fons Dams
      Member

      RTF it was. TXT it now is and it works! Thanx Theunis
      @ Brian: pure magic that script of yours! Exactly what I need! Thanx again
      S

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