Hi Eric
I tried writing script to replace fonts. It worked when I wrote it but occasionally doesn’t. The gist of it is that the documents I was working on had some style sheets and some custom formatted text. Also, not all fonts were available to me, hence the missing fonts bit. Anyway, it seems very complicated and there is probably a bettter way of doing it.
Let me know if any of this is any good
-- as the title suggests this script is to change one family of Helvetica to another
-- if you want something different some tinkering will be required
-- the swap list works like this
-- item 1 - the old family
-- item 2 - the old style
-- item 3 - the new family
-- item 4 - the new style
on run
tell application "Finder"
set filelist to choose file with prompt "Choose your InDesign files for changing Helvetica family." with multiple selections allowed
end tell
repeat with anitem in filelist
tell application "Adobe InDesign CS5"
set user interaction level of script preferences to never interact
open anitem without showing window
changeHelvetica() of me -- runs the handler, of me so that the script runs it, not InDesign
save document 1 -- to anitem
close document 1
set user interaction level of script preferences to interact with all
end tell
end repeat
beep 3
activate me
display alert "Finished!"
end run
on open filelist
repeat with anitem in filelist
tell application "Adobe InDesign CS5"
set user interaction level of script preferences to never interact
open anitem without showing window
changeHelvetica() of me -- runs the handler, of me so that the script runs it, not InDesign
save document 1 to anitem
close document 1
set user interaction level of script preferences to interact with all
end tell
end repeat
beep 3
activate me
display alert "Finished!"
end open
on changeHelvetica()
set swapFontList to {¬
{"Helvetica Neue (T1)", "35 Thin", "Helvetica Neue LT Std", "35 Thin"}, ¬
{"Helvetica Neue (T1)", "45 Light", "Helvetica Neue LT Std", "45 Light"}, ¬
{"Helvetica Neue (T1)", "46 Light Italic", "Helvetica Neue LT Std", "46 Light Italic"}, ¬
{"Helvetica Neue (T1)", "55 Roman", "Helvetica Neue LT Std", "55 Roman"}, ¬
{"Helvetica Neue (T1)", "57 Condensed", "Helvetica Neue LT Std", "57 Condensed"}, ¬
{"Helvetica Neue (T1)", "66 Medium Italic", "Helvetica Neue LT Std", "66 Medium Italic"}, ¬
{"Helvetica Neue (T1)", "75 Bold", "Helvetica Neue LT Std", "75 Bold"}, ¬
{"Helvetica Neue (T1)", "85 Heavy", "Helvetica Neue LT Std", "85 Heavy"}, ¬
{"Helvetica Neue (T1)", "87 Heavy Condensed", "Helvetica Neue LT Std", "87 Heavy Condensed"} ¬
}
-- don't ask me why - it doesn't make any sense
set swapMissingFontList to {¬
{"[Helvetica Neue (T1)]", "35 Thin", "Helvetica Neue LT Std", "35 Thin"}, ¬
{"[Helvetica Neue (T1)]", "45 Light", "Helvetica Neue LT Std", "45 Light"}, ¬
{"[Helvetica Neue (T1)]", "46 Light Italic", "Helvetica Neue LT Std", "46 Light Italic"}, ¬
{"[Helvetica Neue (T1)]", "55 Roman", "Helvetica Neue LT Std", "55 Roman"}, ¬
{"[Helvetica Neue (T1)]", "57 Condensed", "Helvetica Neue LT Std", "57 Condensed"}, ¬
{"[Helvetica Neue (T1)]", "66 Medium Italic", "Helvetica Neue LT Std", "66 Medium Italic"}, ¬
{"[Helvetica Neue (T1)]", "75 Bold", "Helvetica Neue LT Std", "75 Bold"}, ¬
{"[Helvetica Neue (T1)]", "85 Heavy", "Helvetica Neue LT Std", "85 Heavy"}, ¬
{"[Helvetica Neue (T1)]", "87 Heavy Condensed", "Helvetica Neue LT Std", "87 Heavy Condensed"} ¬
}
tell application "Adobe InDesign CS5"
set myDocument to document 1
tell myDocument
set myParaStyles to name of paragraph styles of myDocument
repeat with i from 1 to count of items of myParaStyles
set myFontApplied to name of applied font of paragraph style i
repeat with x from 1 to count of swapFontList
set myFontToChange to ((item 1 of item x of swapFontList) & "\t" & (item 2 of item x of swapFontList))
set myNewFamily to (item 3 of item x of swapFontList)
set myNewStyle to (item 4 of item x of swapFontList)
try
if myFontApplied is equal to myFontToChange then
set properties of paragraph style i to {applied font:myNewFamily, font style:myNewStyle}
end if
end try
end repeat
end repeat
end tell
tell myDocument
set myCharStyles to name of character styles of myDocument
repeat with i from 2 to count of items of myCharStyles
set myFontApplied to applied font of character style i
repeat with x from 1 to count of swapFontList
set myNewFamily to (item 3 of item x of swapFontList)
set myNewStyle to (item 4 of item x of swapFontList)
set myFontToChange to (item 1 of item x of swapFontList)
if myFontApplied is equal to myFontToChange then
set properties of character style i to {applied font:myNewFamily, font style:myNewStyle}
end if
end repeat
end repeat
end tell
-- seems like you have to set styles and fonts separately. and styles first
repeat with x from 1 to count of swapFontList
set myFontToChange to (item 1 of item 1 of swapFontList) -- no need to loop, therefore the first list item is used
set myNewFamily to (item 3 of item 1 of swapFontList) -- ditto
set myOldStyle to (item 2 of item x of swapFontList)
set myNewStyle to (item 4 of item x of swapFontList)
--Clear the find/change preferences.
set find text preferences to nothing
set change text preferences to nothing
--Set the find options.
set case sensitive of find change text options to false
set include footnotes of find change text options to true
set include hidden layers of find change text options to true
set include locked layers for find of find change text options to true
set include locked stories for find of find change text options to true
set include master pages of find change text options to true
set applied font of find text preferences to myFontToChange
set applied font of change text preferences to myNewFamily
set whole word of find change text options to false
set font style of find text preferences to myOldStyle
set font style of change text preferences to myNewStyle
tell myDocument
set myFoundItems to change text
end tell
end repeat
-- and then the font family.
set myFontToChange to (item 1 of item 1 of swapFontList) -- no need to loop, therefore the first list item is used
set myNewFamily to (item 3 of item 1 of swapFontList) -- ditto
set find text preferences to nothing
set change text preferences to nothing
set case sensitive of find change text options to false
set include footnotes of find change text options to true
set include hidden layers of find change text options to true
set include locked layers for find of find change text options to true
set include locked stories for find of find change text options to true
set include master pages of find change text options to true
set whole word of find change text options to false
set applied font of find text preferences to myFontToChange
set applied font of change text preferences to myNewFamily
tell myDocument
set myFoundItems to change text
end tell
--Clear the find/change preferences after the search.
set find text preferences to nothing
set change text preferences to nothing
-- and then do it all again just in case the fonts are missing
repeat with x from 1 to count of swapMissingFontList
set myOldStyle to (item 2 of item x of swapMissingFontList)
set myNewStyle to (item 4 of item x of swapMissingFontList)
--Clear the find/change preferences.
set find text preferences to nothing
set change text preferences to nothing
--Set the find options.
set case sensitive of find change text options to false
set include footnotes of find change text options to true
set include hidden layers of find change text options to true
set include locked layers for find of find change text options to true
set include locked stories for find of find change text options to true
set include master pages of find change text options to true
set whole word of find change text options to false
set font style of find text preferences to myOldStyle
set font style of change text preferences to myNewStyle
tell myDocument
set myFoundItems to change text
end tell
end repeat
-- and then the font family.
set myFontToChange to (item 1 of item 1 of swapMissingFontList) -- no need to loop, therefore the first list item is used
set myNewFamily to (item 3 of item 1 of swapMissingFontList) -- ditto
set find text preferences to nothing
set change text preferences to nothing
set case sensitive of find change text options to false
set include footnotes of find change text options to true
set include hidden layers of find change text options to true
set include locked layers for find of find change text options to true
set include locked stories for find of find change text options to true
set include master pages of find change text options to true
set whole word of find change text options to false
set applied font of find text preferences to myFontToChange
set applied font of change text preferences to myNewFamily
tell myDocument
set myFoundItems to change text
end tell
--Clear the find/change preferences after the search.
set find text preferences to nothing
set change text preferences to nothing
-- mop up the remaining characters
tell myDocument
repeat with i from 1 to count of swapFontList
set findChangeStyle to (item 4 of item i of swapFontList)
set searchFont to "Helvetica Neue (T1)\t" & findChangeStyle
set replaceFont to "Helvetica Neue LT\t" & findChangeStyle
try
set (applied font of every character of every story whose applied font is (font searchFont of application "Adobe InDesign CS5")) to (font replaceFont of application "Adobe InDesign CS5")
end try
end repeat
end tell
end tell
end changeHelvetica
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)