2011-08-11 33 views
8

Próbowałem zrobić to od dłuższego czasu i nie znalazłem skutecznego sposobu, aby to zrobić. Obecnie Próbowałem do listy wszystkich czcionek znam tak:AppleScript - Lista wszystkich czcionek

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

Ale to wymaga zawsze napisać wszystkie czcionki i wiem, że istnieje mnóstwo czcionek na komputerach Mac. Czy istnieje skuteczniejszy sposób na uzyskanie wszystkich czcionek w systemie, napisanie kilku rzeczy w dokumencie tekstowym, a następnie ustawienie czcionki każdej kolejnej linii na następną czcionkę (np. Czcionka linii 1 to czcionka 1, czcionka linii 2 to jest Czcionka 2 itd.)?

Odpowiedz

1

Masz rację, Mac OS X ma mnóstwo czcionek. Te czcionki są dystrybuowane przez cztery lub więcej folderów, w zależności od instalacji oprogramowania i liczby kont użytkowników na komputerze.

+1 na twoje pytanie, jak próbowałem zrobić to samo, więc skomponowałem mały skrypt, który wykonuje tę pracę. Wyciąga czcionki z czterech/pięciu różnych lokalizacji, zapisuje w dokumencie tekstowym, a następnie zmienia czcionki. Jednak po uruchomieniu system może zacząć opóźniać pracę (jak to zrobiłem kilka minut temu). Ale opóźnienie jest tego warte! Oto scenariusz:

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

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 
+0

+1, ponieważ tak zaskakujące, jak się wydaje, nie słyszałem o "Książce z czcionkami" aż do teraz! : P – fireshadow52

+0

To powinno być oznaczone jako poprawna odpowiedź! –

2

Jest polecenia UNIX, które można użyć: system_profiler. Typ danych "SPFontsDataType" da ci tylko czcionki z profilu systemu. -xml przedstawi dane w formacie XML.

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

Możesz przechwycić to w pamięci lub pliku i przeanalizować w dowolnym celu.

+0

Idealny sposób na zaszczepienie kolejnej komendy powłoki: "mdls/path/to/font", która wyświetli wszystkie właściwości czcionki. – Orwellophile

Powiązane problemy