Is the 13.3.1 Font Book No Longer Scriptable?

Hello all –

Running newly installed Ventura, and a reliable Font Book script now no longer works. It shows «class fbfm» and such.

Script Debugger (v8.0.5) shows Font Book as not scriptable, so I’m asking to confirm the worst.

Given that, can I get a text font dump from the new Font Book? Any scriptable substitutes? Any substitutes that do give a font dump?

Thanks.

—Mick

We are aware of FontBook’s scriptability lost in its beta stage one years ago.

And now we can get various font information by using NSFont.

http://piyocast.com/as/archives/tag/nsfont

1 Like

Hi – Thanks. Confirming the worst. :face_with_diagonal_mouth:

NSFont looks like a bridge too far. Another forum provided the way to do it in VBA for Microsoft Word (only). Works in the Mac versions. Happy to provide here if there’s any interest.

…Mick

I think you’d better to complain to Apple not to me.


Yes, please do.

Sorry, more a comment than a complaint. This is what the NSFont page looks like:

アラートダイアログ上のTable Viewで起動中のアプリケーションを選択 v3c

I’m not fluent. It does have your icon on it, so I guess you are.

…Mick

It is my personal blog “AppleScript Hole”.

Hi CC -

This is the relevant page: https://learn.microsoft.com/en-us/office/vba/api/Word.FontNames

This is my test code, which combined all of the examples therein:

Sub fontcount()
    Dim aFont As Variant
    MsgBox PortraitFontNames.Count & " fonts available"
    MsgBox FontNames(1)
    For Each aFont In FontNames
        ActiveDocument.Range.InsertAfter aFont & vbCr
    Next aFont
End Sub

It only runs in MSWord. I tested it in Excel and test unsat. I have about 1600 fonts installed. :slightly_frowning_face: Number 1 is Times New Roman.

…Mick

1 Like

If you’re going to use Word, why not just do it in AppleScript?

tell application "Microsoft Word"
	
	set fontList to font names	
	set fontCount to count of fontList
	
end tell
1 Like
--------------------------------------------------------
property LF : linefeed
--------------------------------------------------------

set AppleScript's text item delimiters to LF

tell application "Microsoft Word"
   
   set fontList to font names as text
   set fontCount to count of fontList
   
   set AppleScript's text item delimiters to {""}
   
   tell active document
      set myRange to create range start 0 end 0
      set content of myRange to "" & fontCount & space & "Fonts Available" & LF & LF & (fontList as text)
   end tell
   
end tell

--------------------------------------------------------
1 Like

Here is an alternative approach that uses the shell’s find to produce a list of fonts drawn from the three regular font folders.

/Users/$USER/Library/Fonts
/Library/Fonts
/System/Library/Fonts

It finds all files in these three folders and then uses grep to exclude the handful of undesirables that may sprout up inside the font folders.

.DS_Store
.uuid
encodings.dir
fonts.

Finally, the result will be a list of every font’s path/name so it then removes everything prior to the final ‘/’ in each entry and separates each font name to its own line. Note that due to the way fonts are named and produced, the names likely won’t match Font Books’ exactly. Fonts have myriad names, there are different formats and some typefaces are crammed into a single file while others have separate file for each variation (e.g. italic, bold-italic).

set ulf to quoted form of POSIX path of (path to library folder from user domain) & "Fonts"
set clf to quoted form of "/Library/Fonts"
set slf to quoted form of "/System/Library/Fonts"

set sCmd to "find " & ulf & " '/Library/Fonts' '/System/Library/Fonts' -type f | grep -Ev '.DS_Store|.uuid|encodings.dir|fonts.'"

set fontText to do shell script sCmd
set fp to paragraphs of fontText
set fnameList to {}
set AppleScript's text item delimiters to "/"
repeat with ef in fp
	set end of fnameList to last text item of ef
end repeat
set AppleScript's text item delimiters to linefeed
fnameList as text
1 Like

.
Following works 14-15 times faster on my Mac:
.

set ulf to quoted form of POSIX path of (path to library folder from user domain) & "Fonts"
set clf to quoted form of "/Library/Fonts"
set slf to quoted form of "/System/Library/Fonts"

set sCmd to "find " & ulf & " '/Library/Fonts' '/System/Library/Fonts' -type f | grep -Ev '.DS_Store|.uuid|encodings.dir|fonts.'"

set fnameList to paragraphs of (do shell script sCmd & " | sed 's/.*\\///g'")
2 Likes

A slight variation on the theme…

set ulFonts to quoted form of (POSIX path of (path to library folder from user domain) & "Fonts")
set clFonts to quoted form of "/Library/Fonts"
set slFonts to quoted form of "/System/Library/Fonts"

set shCmd to "find " & ulFonts & space & clFonts & space & slFonts & " -type f \\
| grep -Ev '.DS_Store|.uuid|encodings.dir|fonts.' \\
| sed 's/.*\\///g'
"

set fileNameList to paragraphs of (do shell script shCmd)
1 Like

Let’s see if we can improve upon that for speed…

--------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2023/04/29 05:27
# dMod: 2023/04/29 05:27 
# Appl: AppleScriptObjC
# Task: List Available Fonts By Name.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @List, @Available, @Fonts, @Name
--------------------------------------------------------
use framework "Foundation"
use scripting additions
--------------------------------------------------------
property LF : linefeed
--------------------------------------------------------

set ulFonts to POSIX path of (path to fonts folder from user domain)
set clFonts to POSIX path of (path to fonts folder from local domain)
set slFonts to POSIX path of (path to fonts folder from system domain)

set AppleScript's text item delimiters to LF
set fontList to ((my findFilesWithRegEx:".+" inDir:ulFonts) ¬
   & (my findFilesWithRegEx:".+" inDir:clFonts) ¬
   & (my findFilesWithRegEx:".+" inDir:slFonts)) ¬
   as text

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on findFilesWithRegEx:findPattern inDir:srcDirPath
   set fileManager to current application's NSFileManager's defaultManager()
   set sourceURL to current application's |NSURL|'s fileURLWithPath:srcDirPath
   set theURLs to fileManager's contentsOfDirectoryAtURL:sourceURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
   set theURLs to theURLs's allObjects()
   set foundItemList to current application's NSPredicate's predicateWithFormat_("lastPathComponent matches %@", findPattern)
   set foundItemList to theURLs's filteredArrayUsingPredicate:foundItemList
   set foundItemList to (foundItemList's valueForKey:"lastPathComponent") as list
end findFilesWithRegEx:inDir:
--------------------------------------------------------

Tested on my Mac. This has the same speed with my script. The AsObjC version is slower than my and your regex versions.

You’re right…

I must have tested with the Foundation framework already loaded (which is faster than the shell script version on my system).

Testing in a freshly launched Script Geek tells a different story.

I still like the AppleScriptObjC, but then again I’m a speed demon – so pure speed often trumps other things…

:sunglasses:

Interesting. The MS Word VBA code found 1,597 fonts on my MacBook, running Ventura. The Applescript code found 290.

I don’t know all the differences yet. But MS Word found all the "Noto” fonts, and Applescript only found half a dozen.

…Mick

1 Like

Offhand, that might imply that the AS script isn’t looking in all the right places but you should provide the Noto results as well as the location of the fonts. I should add that there can also be ‘Fonts Disabled’ folders, which I think are added automatically when you disable fonts.

For myself, I have two Noto typefaces (Sans, Serif) and each has four fonts (regular, bold, italic, bold-italic).

Your VBA script (as well as the Word applescript) returns the two Noto faces but not the individual fonts:

NotoSans
NotoSerif

The shell-based scripts return the eight individual fonts:

NotoSans-Bold.ttf", “NotoSans-BoldItalic.ttf”, “NotoSans-Italic.ttf”, “NotoSans-Regular.ttf”, “NotoSerif-Bold.ttf”, “NotoSerif-BoldItalic.ttf”, “NotoSerif-Italic.ttf”, “NotoSerif-Regular.ttf”

Also, as I mentioned previously, a number of fonts will have different counts depending upon the method used and how the fonts are packaged. As you can see above, Noto is a good example of this. The CJK fonts are also prone to this. Hiragino (ヒラギノ) is a prime example.

1 Like

Your original question was about how Font Book.app is no longer scriptable and how to get system-installed fonts rather than those that might be built into a particular application and not shared with the system.

Microsoft Word may have thousands of fonts, but that does not mean that they are installed or that they are ever listed in Font Book.app. Most of them is not shared with system, so can be used only inside the tell block of application.

In addition, installed fonts (listed by Font Book.app ) may be located in several other locations than those indicated by @Mocman. To find all these folders on your Mac, you can again use the find command. Or, search in Finder with “Kind is Folder” + “Name ends with “Fonts””. On my Mac I found 9 locations.

1 Like

The list of Noto fonts installed by Ventura is here: https://support.apple.com/en-us/HT213266. VBA found

  1. Noto Nastaliq Urdu
  2. Noto Sans Kannada Thin
  3. Noto Sans Kannada ExtraLight
  4. Noto Sans Kannada Light
  5. Noto Sans Kannada
  6. Noto Sans Kannada Medium
  7. Noto Sans Kannada SemiBold
  8. Noto Sans Kannada ExtraBold
  9. Noto Sans Kannada Black
  10. Noto Sans Myanmar Thin
  11. Noto Sans Myanmar ExtLt
  12. Noto Sans Myanmar Light
  13. Noto Sans Myanmar
  14. Noto Sans Myanmar Med
  15. Noto Sans Myanmar SemBd
  16. Noto Sans Myanmar ExtBd
  17. Noto Sans Myanmar Blk
  18. Noto Sans Zawgyi Thin
  19. Noto Sans Zawgyi ExtLt
  20. Noto Sans Zawgyi Light
  21. Noto Sans Zawgyi
  22. Noto Sans Zawgyi Med
  23. Noto Sans Zawgyi SemBd
  24. Noto Sans Zawgyi ExtBd
  25. Noto Sans Zawgyi Blk
  26. Noto Sans Oriya
  27. Noto Serif Myanmar Thin
  28. Noto Serif Myanmar ExtLt
  29. Noto Serif Myanmar Light
  30. Noto Serif Myanmar
  31. Noto Serif Myanmar Med
  32. Noto Serif Myanmar SemBd
  33. Noto Serif Myanmar ExtBd
  34. Noto Serif Myanmar Blk

Which is five fonts

  1. Noto Nastaliq Urdu
  2. Noto Sans Kannada
  3. Noto Sans Zawgyi
  4. Noto Sans Oriya
  5. Noto Serif Myanmar

And is 26 of the 40 on Apple’s list. Apple does not show the 8-member Zawgyi group.

On the otherhand, VBA does not show 19 of Apple’s list. These are mostly font variants, but it includes the full Noto Serif Kannada font. (At the moment I’d think the two lists should total 40, but Excel says no.)

My conclusion is that this is a harder chore than it needs to be. Personally, I don’t have a need for these sorts of fonts and wish Apple made them download-optional. I do have a want for an accurate list. Just don’t know how to find it. :face_with_diagonal_mouth:

…Mick