How do I programatically install a font on a Macintosh?

6

How do I install fonts programatically on a Mac? And what steps are necessary?

I want to create a program that takes a font file and installs it on the Client's Mac.

Avram

Posted 2010-03-16T19:22:22.650

Reputation: 173

Answers

5

My previous answer was for the unedited question. To answer the new question of how to install fonts programatically on a Mac, Rich's answer is correct, just move them into the fonts folder.

EDIT: To fit within the spirit of my previous answer, here's a (roughly done) AppleScript which will install a font file located at /some/path/to/a/font_file.ttf by using the OS X application "Font Book"

set theFontPath to "/some/path/to/a/font_file.ttf"

set theFont to POSIX file theFontPath

tell application "Finder"
 open theFont
end tell

tell application "Font Book"
 activate
 set theFontWindow to the first window
end tell

tell application "System Events"
 tell process "Font Book"
  tell window 1
   tell group 1
    click button "Install Font"
   end tell
  end tell
 end tell
end tell

This could be executed in C++ via the osascript command; if you need help with that, it's a separate question altogether. Or you could do as Rich suggested and just move the file using the C rename() function.


Previous answer (for reference purposes only):

I suggest using the "Font Book" program located in /Applications. In addition to automatically coping the font to the proper font folders (outlined in Rich Bradshaw's answer) Font Book will verify the font before installing. Fonts are notorious for being corrupt and causing issues. In addition, Font Book shows the fonts which are installed and allows you to disable them.

To add fonts using Font Book, open the application and choose "Add Fonts" from the "File" menu. Before doing this I highly recommend to choose "Preferences" from the "Font Book" menu and ensure that "Validate fonts before installing" is enabled. Also, here you can decide if the fonts will be installed just for the current user, or for all users of the computer.

Josh

Posted 2010-03-16T19:22:22.650

Reputation: 7 540

Hi Josh, the question is moved to the superuser by mistake. anyway your answer looks exacly like i found in most forums. – Avram – 2010-03-16T22:06:56.410

12

Move the font to ~/Library/Fonts, or if you want it available system wide and have root permissions, /Library/Fonts.

Rich Bradshaw

Posted 2010-03-16T19:22:22.650

Reputation: 6 324