Indesign CS 5.5 - Font replacer

Hi all,

I’m looking to create a fairly simple script to replace fonts in 100’s of Indesign CS 5.5 documents. I’ve scoured MacScripter but cannot seem to find what I’m needing.

Basically I need to search for two specific fonts, that are common on all documents, and replace them with another font.

Example:

Find all text in all stories that contain Helvetica - Bold and replace with Times - Italic

I found the following but this is actually just changing one particular glyph. I’m needing all characters changed.

Any help would be appreciated.

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

I have found a much more efficient way of handling this which i will include below.

tell application "Adobe InDesign CS5.5"
	-- clear existing settings
	set properties to {find text preferences:nothing, change text preferences:nothing}
	-- set option
	set properties of find change text options to {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}
	--set up new settings
	set properties of find text preferences to {applied font:"Myriad Pro", font style:"Regular"}
	set properties of change text preferences to {applied font:"Frutiger", font style:"57 Condensed"}
	-- make the change
	change text document 1
end tell

Any help on how to make this run on a large number of files in a folder would be greatly appreciated.

Thanks in advance.

Well I solved my problem myself…haha. took hours but it’s done. Posting here for future inquiries on the subject. Thanks for letting me rant.

tell application "Finder"
	set myInFolder to choose folder with prompt "Select a folder"
	set myFilelist to files in myInFolder whose name ends with ".indd"
end tell

tell application "Adobe InDesign CS5.5"
	set user interaction level of script preferences to never interact
	repeat with myDoc from (count myFilelist) to 1 by -1
		set myCurrentFile to item myDoc of myFilelist
		open myCurrentFile
		set myCurDocument to active document
		tell myCurDocument
			
			tell application "Adobe InDesign CS5.5"
				-- clear existing settings
				set properties to {find text preferences:nothing, change text preferences:nothing}
				-- set option
				set properties of find change text options to {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}
				--set up new settings
				set properties of find text preferences to {applied font:"Myriad Pro", font style:"Regular"}
				set properties of change text preferences to {applied font:"Gotham", font style:"Bold"}
				-- make the change
				change text document 1
			end tell
			
			close saving yes -- save and close  
		end tell
	end repeat
	set user interaction level of script preferences to interact with all
	beep 3
	display alert "Finished!"
end tell

Hello,

Overall, your script is fine. Just a few notes: no need to tell application “Adobe InDesign CS5.5” twice like you did here:

tell application "Adobe InDesign CS5.5"
   set user interaction level of script preferences to never interact
   repeat with myDoc from (count myFilelist) to 1 by -1
       set myCurrentFile to item myDoc of myFilelist
       open myCurrentFile
       set myCurDocument to active document
       tell myCurDocument
           
           tell application "Adobe InDesign CS5.5"

You can remove the second one.

And this:

set properties of find change text options to {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}

you only need to tell once per “session”. So move it right before the beginning of your repeat loop, but still inside the tell app. block. It will save a little bit of time. Only put things inside a repeat loop that absolutely need to be there or change because of the loop.

Also, might not work, but I think you can change these two lines:

open myCurrentFile
set myCurDocument to active document

to only this:

set myCurDocument to open myCurrentFile

again, will save a bit of time by assigning the document to be opened to the variable right away.

I migt be missing other stuff, but this is what is apparent to me for now.

Cheers!

Browser: Safari 534.51.22
Operating System: Mac OS X (10.8)

Hi leonsimard,

Thank you so much for replying! I applied several of your comments to the script and it is indeed much faster. It never amazes me how many different ways you can skin a cat.

I appreciate it very much.

You’re welcome. Glad I could help. :slight_smile:

Since Adobe will no longer be supporting Type 1 fonts, I had to do something very similar. So here’s my version of an AppleScript inDesign font replacer

set fontReplacements to {¬
   ({findFontName:"Benton Gothic" & tab & "Bold", findFontStyle:"Bold", changeFontName:"BentonGothic-Bold   Bold", changeFontStyle:"Bold"}), ¬
   ({findFontName:"Benton Gothic" & tab & "Regular", findFontStyle:"Regular", changeFontName:"BentonGothic-Regular   Regular", changeFontStyle:"Regular"}) ¬
      }
tell application "Adobe InDesign 2023"
   --  settings and option
   set properties to {find text preferences:nothing, change text preferences:nothing}
   set properties of find change text options to {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}
   
   repeat with thisReplacement in fontReplacements
      set fontToFind to findFontName of thisReplacement
      set fontToFindStyle to findFontStyle of thisReplacement
      set changeFont to changeFontName of thisReplacement
      set changeFontStyle to changeFontStyle of thisReplacement
      set properties of find text preferences to {applied font:fontToFind, font style:fontToFindStyle}
      set properties of change text preferences to {applied font:changeFont, font style:changeFontStyle}
      change text active document
   end repeat
end tell