Font Book - Deactivate Fonts

Hi,

I tried Automator to disable specific font in Font Book but I figured with a big deception that this is very unstable application.

Sometimes this work and the other time (most of it) this not work and it disable not the entire typeface. The “Deactivate Fonts” action work randomly. I will say this work 1 time of 15. I get an error like this one: “An error (Font Book got an error: NSReceiverEvaluationScriptError: 4 (1)) occured in Deactivate Fonts”. Someone can explain to me why? I cannot trust Automator and now I need a pure AppleScript script solution.

Can you help me?

For my example I want to disable the “Skia” font family.

Thank you very much in advance for helping me!

Hi

Try this…

tell application "Font Book"
	activate
	set myFonts to {"Al Bayan Bold", "Al Bayan Plain", "Skia Regular"}
	set fontNames to name of typefaces
	repeat with i from 1 to count myFonts
		set fontName to item i of myFonts
		try
			set enabled of typeface fontName to false
		end try
	end repeat
end tell

Instead of the Al Bayan fonts, type whatever other typeface names you want deselected.

Pirri

Thanks for this fast answer but if, for example, I want to disable the “Al Bayan” family how I do it? I don’t want or need to disable each sub parts of the font like regular, bold, italic, etc. It is possible? Check “Baskerville” this is an excellent example of many different parts. :slight_smile:

Try something like this, Frédéric:

tell application "Font Book" to set enabled of typefaces of font family "Al Bayan" to false

Exactly what I needed! Except when Font Book is not already open the script get an error. :frowning: I think I will needed and validate that the application is open and load before doing it. It is possible to do that?

Thank you very much! :smiley:

Interesting, Kai. On my system [10.4.6] I get an error: ‘Font Book got an error: Can’t set enabled of every typeface of font family "Al Banyan to false.’ Variations on that theme fail as well.

Exact! This is the same error I got with Automator and AppleScript. The problem is maybe the Font Book application itself.
The only difference, I have far more control with AppleScript. A delay is not a solution because if you have a slow computer you will need more delay. That’s why I asked if this is possible to check in loop if the application is completly load before deactivate a font. I think this can be a good a workaround.

This might do the trick, Frédéric:

tell application "Font Book" to tell font family "Al Bayan"
	repeat until exists
		delay 0.2
	end repeat
	set enabled of typefaces to false
end tell

Yours does the trick for me, Kai, but neither of Jacques’ formulations would work for me - Al Bayan remained active although no error was reported. I think the “wait until exists” is the key - the Font Book seems slow to gather its info.

Thanks for the confirmation, Adam. (I wasn’t sure if it would fix things for you, since the only error I could manage here was our old friend “NSReceiverEvaluationScriptError: 4”.)

The solution work perfectly now (I guess! :cool:).

Thanks for all your help, this is appreciated!