Dennis
Dennis

Reputation: 81

AppleScript - List all fonts

I've been trying to do this for quite some time, and haven't found an efficient way to do it. Currently I've been trying to list all the fonts I know like this:

set the font_list to {"Arial","Comic Sans MS","Arial Black",...}

But it takes forever to write all the fonts and I know that there are tons of fonts on the Mac. Is there a more efficient way to get all the fonts on the system, write a bunch of stuff in a text document, and then set the font of each consecutive line to the next font (i.e. Line 1's font is Font 1, Line 2's font is Font 2, etc.)?

Upvotes: 8

Views: 2596

Answers (3)

skibster
skibster

Reputation: 19

There is a unix command that you can use: system_profiler. The data type of "SPFontsDataType" will give you just fonts from the system profile. The -xml will present the data in XML.

system_profiler -xml SPFontsDataType > ~/Desktop/myfonts.plist

You can capture this in memory or to a file and parse it for whatever purpose you need.

Upvotes: 2

fireshadow52
fireshadow52

Reputation: 6516

You are correct in that the Mac OS X has tons of fonts. These fonts are distributed through four or more folders, depending on software installation and the number of user accounts on your computer.

+1 to your question as I've been trying to do the same thing, so I composed a little script that does the job. It pulls fonts from four/five different locations, writes in a text document, then changes the fonts. However, when you run it, your system may start lagging (as mine did a few moments ago). But the lag is worth it! Here is the script:

--"get all the fonts on the system"

display dialog "WARNING" & return & return & "This script may cause your computer to lag. Are you sure you want to proceed with the font sampler?" with icon caution
set the font_folders to {"/Users/" & the short user name of (system info) & "/Library/Fonts/", "/Library/Fonts/", "/Network/Library/Fonts/", "/System/Library/Fonts/", "/System Folder/Fonts/"}
set these_fonts to {}
repeat with this_font_folder in the font_folders
    try
        tell application "Finder" to set the end of these_fonts to every item of ((this_font_folder as POSIX file) as alias)
    end try
end repeat

--"write a bunch of stuff in a text document"

tell application "TextEdit"
    activate
    set zoomed of the front window to true
    set the name of the front window to "Font Sampler"
end tell
repeat with this_font in these_fonts
    tell application "Finder" to set this_font to the name of this_font
    tell application "TextEdit" to set the text of document 1 to the text of document 1 & this_font & ":    The quick brown fox jumps over the lazy dog." & return
end repeat

--"set the font of each consecutive line to the next font (i.e. Line 1's font is Font 1, Line 2's font is Font 2, etc.)"

repeat with i from 1 to the count of these_fonts
    tell application "Finder" to set this_font to the name of item i of these_fonts
    tell application "TextEdit" to tell paragraph i of the text of document 1 to set the font to this_font
end repeat

Upvotes: 1

Lri
Lri

Reputation: 27613

 tell application "Font Book" to name of font families

set l to {"Regular", "Roman", "Book", "Plain", "55 Roman", "R"}
set found to {}
tell application "Font Book"
    repeat with x in typefaces
        if l contains style name of x then set end of found to name of x
    end repeat
end tell
found

Upvotes: 3

Related Questions