Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change fonts using AppleScript

New Here ,
Jul 03, 2012 Jul 03, 2012

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?

TOPICS
Scripting
4.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 04, 2012 Jul 04, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2012 Jul 06, 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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 12, 2012 Jul 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}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2012 Jul 16, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines