2

For a macOS software that works with fonts on the bash shell I need information about the installed fonts. To get the font information I use

system_profiler SPFontsDataType

This works fine on an English macOS. However when run on a German macOS it outputs everything in English, except the font style. And for compatibility I also need the font style in English.

Example German macOS:

Full Name: Times New Roman Fett
Family: Times New Roman
Style: Fett

Example English macOS:

Full Name: Times New Roman Bold
Family: Times New Roman
Style: Bold

I tried to set to change AppleLanguages in the defaults for system_profiler, but it didn't work. The output was still in German:

defaults write com.apple.systemprofiler AppleLanguages '("en-US","de-DE")'

defaults write com.apple.systemprofiler AppleLanguages -array "en-US" "de-DE"

However when I temporarily set the NSGlobalDomain to English it worked:

tempvalues=$(defaults read NSGlobalDomain AppleLanguages)
defaults write NSGlobalDomain AppleLanguages -array "en-US" 
system_profiler SPFontsDataType
defaults write NSGlobalDomain AppleLanguages "$tempvalues"

But isn't there a better approach than changing the NSGlobalDomain? Calling system_profiler takes a few seconds, so it might affect other programs too.

From the fonts I need: the full name, family, style, file name and location (=full path), version, copy protected field, embeddable field. All this info is available in SPFontsDataType.

New contributor
mart5 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • It would be useful if you would list the information you're trying to obtain (and even why the app needs it).
    – benwiggy
    Sep 22 at 13:15

1 Answer 1

2

I'd suggest it's much easier to use NSFontManager than trying to use the localised information from System Profiler.

Here's a Swift script that produces a list of the PostScript names of every installed font.

#!/usr/bin/swift    
import AppKit
    
    let manager = NSFontManager.shared
    let fontList = manager.availableFonts
    
    print (fontList)

If you just want to check whether a particular font is installed, then there are easy ways of doing that.

However, this is straying into software development, which is off-topic here, and for which Stack Overflow is more appropriate.

3
  • Thank you, but as far as I know NSFontManager doesn't return all necessary font info. For example the file name or the font version string is not available. That's why we use SPFontsDataType.
    – mart5
    Sep 22 at 13:01
  • 1
    @mart5 This is why it's important to explain what you're trying to achieve, rather than what you're doing. Ask "I need to get the following information".
    – benwiggy
    Sep 22 at 13:13
  • I read this entry before posting the question: apple.stackexchange.com/questions/159064 That's why I landed here and not in Stack Overflow. And I had hoped there was a similar simple solution.
    – mart5
    Sep 22 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .