2011-08-11 43 views
8

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

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

但它需要永远写所有的字体,我知道有吨在Mac上的字体。有没有更有效的方法来获取系统中的所有字体,在文本文档中写入一堆东西,然后将每个连续行的字体设置为下一个字体(例如,第1行的字体是字体1,第2行的字体是字体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 
3
tell application "Font Book" to name of font families 

​​
+0

+1因为看起来令人惊讶,直到现在我还没有听说过'Font Book'! :P – fireshadow52

+0

这应该被标记为正确答案! –

2

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

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

您可以将其捕获到内存或文件中,并解析它,无论您需要什么目的。

+0

种子另一个shell命令的完美方式:“mdls/path/to/font”,它将列出所有的字体属性。 – Orwellophile