2011-08-11 38 views
8

Tôi đã cố gắng làm điều này trong một thời gian và không tìm được cách hiệu quả để thực hiện nó. Hiện nay tôi đã cố gắng để liệt kê tất cả các phông chữ tôi biết như thế này:AppleScript - Liệt kê tất cả các phông chữ

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

Nhưng phải mất mãi mãi để viết tất cả các phông chữ và tôi biết rằng có những tấn phông chữ trên Mac. Có cách nào hiệu quả hơn để có được tất cả các phông chữ trên hệ thống hay không, viết một loạt nội dung trong tài liệu văn bản và sau đó đặt phông chữ của từng dòng liên tiếp thành phông chữ tiếp theo (ví dụ: Phông chữ của Dòng 1 là Phông chữ 1, Phông chữ của Dòng 2 là Phông chữ 2, v.v.)?

Trả lời

1

Bạn đúng khi Mac OS X có nhiều phông chữ. Những phông chữ này được phân phối thông qua bốn hoặc nhiều thư mục, tùy thuộc vào cài đặt phần mềm và số lượng tài khoản người dùng trên máy tính của bạn.

+1 cho câu hỏi của bạn vì tôi đã cố gắng làm điều tương tự, vì vậy tôi đã soạn một tập lệnh nhỏ thực hiện công việc. Nó kéo phông chữ từ bốn/năm vị trí khác nhau, viết trong một tài liệu văn bản, sau đó thay đổi phông chữ. Tuy nhiên, khi bạn chạy nó, hệ thống của bạn có thể bắt đầu tụt hậu (như tôi đã làm một vài phút trước). Nhưng độ trễ là giá trị nó! Đây là kịch bản:

--"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 vì đáng ngạc nhiên vì có vẻ như, tôi chưa nghe nói về 'Font Book' cho đến bây giờ! : P – fireshadow52

+0

Điều này sẽ được đánh dấu là câu trả lời đúng! –

2

Có một lệnh unix mà bạn có thể sử dụng: system_profiler. Kiểu dữ liệu của "SPFontsDataType" sẽ cung cấp cho bạn chỉ các phông chữ từ cấu hình hệ thống. The -xml sẽ trình bày dữ liệu trong XML.

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

Bạn có thể ghi hình này vào bộ nhớ hoặc tệp và phân tích cú pháp cho bất kỳ mục đích nào bạn cần.

+0

Cách hoàn hảo để thêm một lệnh shell khác: "mdls/path/to/font" sẽ liệt kê tất cả các thuộc tính phông chữ. – Orwellophile

Các vấn đề liên quan