Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)?

like image 875
Dennis Avatar asked Aug 11 '11 21:08

Dennis


People also ask

What are Apple system fonts?

SF Pro is the system font in iOS and iPadOS.

Is Helvetica a system font on Mac?

Designed on a Mac, Helvetica Neue looks chic. But the Mac version of the font is proprietary to the Mac. It is installed at the system level in the “dfont” format. It isn't compatible with PCs (which swap it with Arial or another Windows system font).

Is Garamond a Mac font?

Apple Garamond is a serif typeface used by Apple as their main branding font over the course of nearly two decades. The design was based off ITC Garamond but condensed to 80% of its normal width.


3 Answers

 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
like image 100
Lri Avatar answered Dec 17 '22 03:12

Lri


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.

like image 22
skibster Avatar answered Dec 17 '22 04:12

skibster


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
like image 45
fireshadow52 Avatar answered Dec 17 '22 02:12

fireshadow52