AppleScript - 列出所有字体

时间:2011-08-11 21:35:10

标签: fonts applescript

我一直试图这样做很长一段时间,并没有找到一种有效的方法来做到这一点。目前我一直试图列出我所知道的所有字体:

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

但是编写所有字体需要永远,我知道Mac上有大量字体。是否有更有效的方法来获取系统上的所有字体,在文本文档中写入一堆东西,然后将每个连续行的字体设置为下一个字体(即第1行的字体是字体1,第2行的字体是字体2等)?

3 个答案:

答案 0 :(得分:3)

 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

答案 1 :(得分:2)

您可以使用unix命令:system_profiler。 “SPFontsDataType”的数据类型将为您提供系统配置文件中的字体。 -xml将以XML格式显示数据。

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

您可以在内存或文件中捕获它,并根据您的需要解析它。

答案 2 :(得分:1)

你是对的,因为Mac OS X有很多字体。这些字体通过四个或更多文件夹分发,具体取决于软件安装和计算机上的用户帐户数。

+1你的问题,因为我一直在尝试做同样的事情,所以我编写了一个小脚本来完成这项工作。它从四个/五个不同位置提取字体,在文本文档中写入,然后更改字体。但是,当你运行它时,你的系统可能会开始滞后(就像我刚刚做的那样)。但是滞后是值得的!这是脚本:

--"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