4 Replies Latest reply on Jul 16, 2012 7:24 AM by Studio1540

    Change fonts using AppleScript

    Studio1540 Level 1

      I want to change every occurance of a typeface to another. In QuarkXPress, the syntax was:

       

      set the font of every character of every text box where font is "Zapf Dingbats" to "Times"

       

      I've tried the same logic and the find/change commands but have not had any luck ... can anyone guide me on this one?

        • 1. Re: Change fonts using AppleScript
          Muppet Mark Level 5

          You need to look for applied font

           

          tell application "Adobe InDesign CS5"

            activate

            --get name of fonts

                    set someFont to some font

                    tell the active document

                              set applied font of every character of every story to someFont

                    end tell

          end tell

          • 2. Re: Change fonts using AppleScript
            Studio1540 Level 1

            Hi Mark,

             

            Thanks for the reply, but this doesn't do what I'm looking for. In this example, every font of every story is changed. What I'm looking to do is change only the fonts where the applied font is "Zapf Dingbats" to "Times" ...

             

            I'm sure this is possible, but for the life if me, I can't figure it out.

             

             

            ==============================================================================

            Here's what I've tried, with some degree of success:

             

            tell application "Adobe InDesign CS5.5"

                activate

                if not (exists active document) then

                    display dialog "No document is open." with icon 2

                else

                    set myDocument to active document

                    set myClass to class of active spread of layout window 1 of myDocument as string

                    if myClass is "master spread" then

                        display dialog "This script does not work on master pages. Switch to a regular layout page and try again." buttons {"Cancel"} default button 1 with icon 2

                    else

                        set user interaction level of script preferences to never interact

                        set find text preferences to nothing

                        set change text preferences to nothing

                        set find grep preferences to nothing

                        set change grep preferences to nothing

                        set find object preferences to nothing

                        set find object preferences to nothing

                        set find glyph preferences to nothing

                        set change glyph preferences to nothing

                        set properties of find glyph preferences to {applied font:"Zapf Dingbats", font style:"Regular", glyph ID:"81"}

                        set properties of change glyph preferences to {applied font:"Times", font style:"Regular", glyph ID:"81"}

                        change glyph

                        set user interaction level of script preferences to interact with all

                    end if

                end if

            end tell

             

            During runtime, I get an AppleScript error that states: "Adobe InDesign CS5.5 got an error: Invalid Find Glyph"

             

            Here's the kicker ... if I set all my options in the Find/Change dialog window and comment out the following lines, it works, so I must be close:

             

            set find text preferences to nothing

            set change text preferences to nothing

            set find grep preferences to nothing

            set change grep preferences to nothing

            set find object preferences to nothing

            set find object preferences to nothing

            set find glyph preferences to nothing

            set change glyph preferences to nothing

             


            • 3. Re: Change fonts using AppleScript
              SuperMacGuy Level 2

              Your glyph ID can't be text, it has to be a number, so no quote marks.

              {applied font:"Times", font style:"Regular", glyph ID:81}

              • 4. Re: Change fonts using AppleScript
                Studio1540 Level 1

                ah ha! That did the trick, and I should have realized that I was using a string and not an integer ... thanks, Guy