Scripting Font Book

Hoping to find a fairly simple way to generate a report of fonts managed by Font Book.

I would like to generate a plain text report of all fonts that are active and separate report to generate a list of all fonts that are turned off.

Is this possible?

Thanks.

Model: G5
Browser: Firefox 21.0
Operating System: Mac OS X (10.7)

Hi,

Hopefully this should give you what you want:

do shell script "echo > " & quoted form of POSIX path of ((path to desktop as string) & "Active Fonts.txt")
do shell script "echo > " & quoted form of POSIX path of ((path to desktop as string) & "Inactive Fonts.txt")

tell application "Font Book"
	set activeFontsList to name of every font family whose enabled is true
	repeat with thisActiveFont in activeFontsList
		do shell script "echo " & quoted form of thisActiveFont & " >> " & quoted form of POSIX path of ((path to desktop as string) & "Active Fonts.txt")
	end repeat
	
	set inactiveFontsList to name of every font family whose enabled is false
	repeat with thisInactiveFont in inactiveFontsList
		do shell script "echo " & quoted form of thisInactiveFont & " >> " & quoted form of POSIX path of ((path to desktop as string) & "Inactive Fonts.txt")
	end repeat
end tell

Thanks,
Nik

That’s almost it.

At first I ran the script as it was, but it timed out and never produced any results. Possibly too many fonts.

I commented out the code for all the active fonts, and it produced a list for the inactive fonts.

What it reported were the families that were inactive, but ignored the families that were active, but had duplicates that were inactive.

If it’s possible to get all inactive fonts, let me know.

I will see if I can figure it out.

Thanks!

I changed:

set inactiveFontsList to name of every font family whose enabled is false

To:

set inactiveFontsList to name of every typeface whose enabled is false

…and that seems to have worked.

Thanks! I would not have been able to get even this simple script together without a lot of wasted time.

Here’s a slightly faster version of blend3’s script:

tell application "Font Book" to set {fontNames, fontEnableds} to {name, enabled} of font families

set activeFontsList to {}
set inactiveFontsList to {}
repeat with i from 1 to (count fontEnableds)
	if (item i of fontEnableds) then
		set end of activeFontsList to item i of fontNames
	else
		set end of inactiveFontsList to item i of fontNames
	end if
end repeat

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set activeFontsList to activeFontsList as text
set inactiveFontsList to inactiveFontsList as text
set AppleScript's text item delimiters to astid

set desktopPath to (path to desktop as text)
writeFile of activeFontsList to (desktopPath & "Active Fonts.txt")
writeFile of inactiveFontsList to (desktopPath & "Inactive Fonts.txt")

on writeFile of txt to destPath
	set accessRef to (open for access file destPath with write permission)
	try
		set eof accessRef to 0
		write txt to accessRef as «class utf8»
	end try
	close access accessRef
end writeFile

Fontbook isn’t exactly a race-horse before all the fonts are loaded.

I find it strange that font family works with Nigel’s script, and not blend’s.

Nigel’s script took 4 seconds, when nothing was loaded. I clocked in blend’s script to 11 seconds, under approx the same conditions.

Hello.

I took some liberties with Nigel’s script, as it is still not so fast, (but probably can’t be much faster) and incorporated StefanK’s SKProgressBar, so you can see that something is happening, and realize when the operation is done.

-- StefanK's SKProgressBar: http://macscripter.net/viewtopic.php?pid=160302#p160302
-- DJ Bazzie Wazzie SKProgressBar code http://macscripter.net/viewtopic.php?id=40763
tell application "SKProgressBar"
	set floating to true
	set position to {600, 550}
	set width to 300.0
	set title to "Gathering Font Data"
	set header to "Searching.."
	set header alignment to left
	set footer to "Determining active and inactive Fonts."
	set footer alignment to right
	set show window to true
	tell progress bar
		activate
		set indeterminate to true
		start animation
	end tell
end tell

tell application "Font Book" to set {fontNames, fontEnableds} to {name, enabled} of font families
set activeFontsList to {}
set inactiveFontsList to {}
repeat with i from 1 to (count fontEnableds)
	if (item i of fontEnableds) then
		set end of activeFontsList to item i of fontNames
	else
		set end of inactiveFontsList to item i of fontNames
	end if
end repeat

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set activeFontsList to activeFontsList as text
set inactiveFontsList to inactiveFontsList as text
set AppleScript's text item delimiters to astid

set desktopPath to (path to desktop as text)
writeFile of activeFontsList to (desktopPath & "Active Fonts.txt")
writeFile of inactiveFontsList to (desktopPath & "Inactive Fonts.txt")
tell application "SKProgressBar"
	stop animation
	set show window to false
	quit
end tell
on writeFile of txt to destPath
	set accessRef to (open for access file destPath with write permission)
	try
		set eof accessRef to 0
		write txt to accessRef as «class utf8»
	end try
	close access accessRef
end writeFile

His produced the same results, at least for me.

I changed his to typeface as well.

Both seemed to work fine; it seemed that Nigel’s was a little faster.

Thanks!