InDesign Replace Missing (Pink) Fonts - Automatically Based on Font Name

Hello all,

I am trying to automatically replace missing fonts based on the name of the missing font.

For instance, InDesign will read the missing font as [Aachen (T1)], with a font style of [Bold].

What I wish to do is replace all instances of this missing Aachen with a new OTF version that is loaded on my machine.

The problem seems to be related to how the InDesign document remembers and honors the font that was once missing when doing the replacement.

In other words, the script below does NOT fail to make the replacement (it works), but the replacement font is incorrect, since it uses: [Aachen (T1)] once again (and it is still considered missing).

But let’s assume the intial font I wished to replace was something (not missing), such as “Myriad Pro Bold” – and also assume that I updated the script so it is looking for “Myriad Pro Bold”. - In doing so, all instances of “Myriad Pro Bold” would successfully be updated to the correcct OTF version “Aachen Bold” that is loaded on my machine.

I hope I was able to explain this odd InDesign behavior in terms of holding on and using a missing font when it should not.

Any help would be greatly appreciated.
Thanks in advance,
-Jeff

tell application id "InDn"
	set thePairs to {{("Aachen (T1)" & tab & "Bold"), ("Aachen" & tab & "Bold")}, ¬
		{("Belizio" & tab & "Regular"), ("Arial" & tab & "Regular")}, ¬
		{("Belizio" & tab & "RegularItalic"), ("Arial" & tab & "Italic")}, ¬
		{("BentonGothic-Bold" & tab & "Bold"), ("Arial Narrow" & tab & "Bold")}, ¬
		{("BentonGothic-Regular" & tab & "Regular"), ("Arial Narrow")}}
	tell active document
		repeat with aPair in thePairs
			set {oldFont, newFont} to aPair
			set theStyles to all paragraph styles
			repeat with aStyle in theStyles
				if exists applied font of aStyle then if name of applied font of aStyle = oldFont then set applied font of aStyle to newFont
			end repeat
			set theStyles to all character styles
			repeat with aStyle in theStyles
				if exists applied font of aStyle then if name of applied font of aStyle = oldFont then set applied font of aStyle to newFont
			end repeat
			if exists (text style ranges of stories whose name of applied font = oldFont) then
				set theRanges to object reference of (text style ranges of stories whose name of applied font = oldFont)
				repeat with aRange in theRanges
					set applied font of aRange to newFont
				end repeat
			end if
		end repeat
	end tell
end tell