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.
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. Number 1 is Times New Roman.
--------------------------------------------------------
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
--------------------------------------------------------
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
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'")
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)
--------------------------------------------------------
# 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:
--------------------------------------------------------
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:
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.
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.
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.