Remove a font library in Font Book

Can anyone advise how to remove a font library from Font Book? I can list them (confusing how some are class domain, and others class font library), I can disable them, but when I try to remove the library I get an error:


tell application "Font Book"
  set x to every font library
  --{font domain "AllFonts" of application "Font Book", font domain "User" of application "Font Book", font domain "Computer" of application "Font Book", font domain "Network" of application "Font Book", font library "My Extra Fonts" of application "Font Book"}
  set y to font library "My Extra Fonts"
  set enabled of y to false
  remove y
end tell

Err message: (null) “(null)” can not be modified.
Err number: -5

The dictionary for Font Book has a command:

remove reference from reference

but I cannot figure out what reference it needs to be able to remove the library.

This would be the equivalent of right clicking the Library in Font Book and choosing: Delete “”.

Thanks.

Hello.

If you run the snippet below, you’ll see that you in fact have three different font folders. With different rights.
Your fonts may also have different rights and ownerships connected to them. Since you may not have enough rights to delete every font file, if you are not having administrator rights for the font,

set a to path to fonts folder from user domain
log a
set b to path to fonts folder from local domain
log b
set c to path to fonts folder from system domain
log c

Reading the dictionary for fontbook, it seems to me that you can only enable/disable a library, but you make get/make/delete a font library object (font collection, font family, typeface).

I can use make to create a new font library, but I can’t delete (error is: Font Book got an error: AppleEvent handler failed.) or remove (error is: (null) “(null)” can not be modified.)

What I’m trying to do is disable a particular font library, which I can do, but then, after it is disabled, I want to remove the library from Font Book.

Is this a bug, or just not possible? Or what might I be missing?


tell application "Font Book"
	make new font library with properties {name:"Second Library"}
	delay 5
	set y to every font library
-- {font domain "AllFonts" of application "Font Book", font domain "User" of application "Font Book", font domain "Computer" of application "Font Book", font library "My Library" of application "Font Book", font library "Second Library" of application "Font Book"}
	set z to font library "Second Library"
	set enabled of z to false

	try
		delete z
	on error errMsg number errNum
		display dialog errMsg & " " & errNum
	end try
	
	try
		remove z
	on error errMsg number errNum
		display dialog errMsg & " " & errNum
	end try
	
end tell

Hello.

Maybe this works like a folder: that you’ll have to remove the contents of the library before you can delete it?

Hi. I’m not certain if it’s a bug, but it could either be that or just an error in the documentation. Add and remove are for font containers”suitcases and such”which is the reasoning for the dual reference points. Delete is the desired command, however, it doesn’t work as expected on font library class objects; it does work on font collections.

tell application "Font Book"
	tell (make new font collection)
		set enabled to false
		delete
	end tell
end tell

Thanks for everyone’s suggestions. Unfortunately, I do need to delete all font libraries, not font collections, so I was forced to loop through any found font libraries and have a user intervene and delete it manually. Luckily this is a script that is triggered with a human being in front of the computer!


set theTest to "gibberish"
repeat until theTest is true
	try
		tell application "Font Book" to set theFontLibraries to font libraries
		set theTest to true
		repeat with i from 1 to count of theFontLibraries
			set theLib to item i of theFontLibraries
			tell application "Font Book"
				set TempTest to theLib is not font domain "All Fonts" and theLib is not font domain "User" and theLib is not font domain "Computer"
				set TempDisplayName to displayed name of theLib
			end tell
			
			if TempTest then
				activate
				display dialog "All Font Book libraries need to be deleted before continuing. Please delete the following:" & return & return & TempDisplayName & return & return & "then press Continue." buttons {"Continue"} default button 1 with title scripttitle giving up after 30
				set theTest to false
			end if
		end repeat
	end try
end repeat