Skip to main content
Participating Frequently
July 3, 2012
Question

Change fonts using AppleScript

  • July 3, 2012
  • 1 reply
  • 4432 views

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?

This topic has been closed for replies.

1 reply

Inspiring
July 4, 2012

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

Participating Frequently
July 6, 2012

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


SuperMacGuy
Known Participant
July 12, 2012

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}