Font Book and deleting disabled fonts

I am trying to delete all disabled fonts that are located in the Macintosh HD:Library:Fonts folder.

I would not attempt to script this if I didn’t have several machines that I would like to do this on.

At this point I’m just trying to get it to list the disabled fonts in just this folder.

This seems to work until I do something like add a “q” to the path:
“/Library/Fonts/q”

There are fonts that begin with Q in this folder.

At that point, I get the following error:
error “Font Book got an error: Can’t get font container of typeface id "file:///Library/Fonts/Didot.dfont#postscript-name=Didot".” number -1728 from font container of typeface id “file:///Library/Fonts/Didot.dfont#postscript-name=Didot”

Any suggestions would be appreciated.

tell application "Font Book"
	
	set disabledFonts to typefaces whose enabled = false
	set disabledCount to count of disabledFonts
	
	repeat with itemNum in disabledFonts
		
		set parentName to path of font container of itemNum
		
		if (parentName as string) contains "/Library/Fonts/q" then
			
			display dialog parentName
			
		end if
		
		
	end repeat
	
end tell

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

Hi. This should give you the font names in a list. If you swap the enabled consideration with the disabled one, I think that would delete the fonts, although that is untested.


set nameList to {}

tell application "Font Book" to repeat with this in (get (typefaces whose enabled = 0)'s ID)
	if (this's contents as POSIX file as text) begins with "Macintosh HD:Library:Fonts:q" then set the end of nameList to typeface id (this's contents)'s name
	--if (this's contents as POSIX file as text) begins with "Macintosh HD:Library:Fonts:q" then delete typeface id (this's contents)
	
end repeat

nameList