python - Come posso trovare il percorso completo di un font dal nome visualizzato su un Mac?

original title: "python - How can I find the full path to a font from its display name on a Mac?"


I am using the Photoshop's javascript API to find the fonts in a given PSD.

Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc.

This is all happening in a python program running on OSX so I guess I'm looking for one of:

  • Some Photoshop javascript
  • A Python function
  • An OSX API that I can call from python

Sto usando l'API javascript di Photoshop per trovare i caratteri in un determinato PSD. Dato un nome di font restituito dall'API, voglio trovare il file di font fisico effettivo a cui corrisponde il nome del font su th ...

Questo è il riepilogo dopo la traduzione, se è necessario visualizzare la traduzione completa, fare clic sull'icona "traduci"

Tutte le risposte
  • Translate

    Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef.

    Cocoa doesn't have any native support, at least as of 10.5, for getting the location of a font.

  • Translate

    open up a terminal (Applications->Utilities->Terminal) and type this in:

    locate InsertFontHere

    This will spit out every file that has the name you want.

    Warning: there may be alot to wade through.

  • Translate

    There must be a method in Cocoa to get a list of fonts, then you would have to use the PyObjC bindings to call it..

    Depending on what you need them for, you could probably just use something like the following..

    import os
    def get_font_list():
        fonts = []
        for font_path in ["/Library/Fonts", os.path.expanduser("~/Library/Fonts")]:
            if os.path.isdir(font_path):
                    [os.path.join(font_path, cur_font) 
                     for cur_font in os.listdir(font_path)
        return fonts

  • Translate

    I haven't been able to find anything that does this directly. I think you'll have to iterate through the various font folders on the system: /System/Library/Fonts, /Library/Fonts, and there can probably be a user-level directory as well ~/Library/Fonts.