path to fonts

Hi, I have created a small applescript to check if a font is installed or not…

tell application "System Events"
	set FontCheck to exists of alias ((path to fonts) & "Myfont.ttf" as string)
end tell

This works well, but my computer has 2 font folders:

#1 My Imac:System:Library:Fonts:bddfont.ttf
#2 My Imac:Library:Fonts:bddfont.ttf

The path to fonts variable gets #1 and I need #2.

Is there a different code to get this path quick without having to add it manually?

Thank you for your time!

Brian

Hi,

the dictionary of System Events contains own relative paths specifiers


tell application "System Events"
	set fontExists to (exists file "Myfont.ttf" of fonts folder of system domain) or (exists file "Myfont.ttf" of fonts folder of local domain)
end tell

nice approach, Thank you!! :smiley:

There is also a fonts folder in every user account.

POSIX path of (path to fonts from user domain) → “/Users/¢¢¢¢¢¢¢¢¢¢/Library/Fonts/”

Yvan KOENIG (VALLAURIS, France) mercredi 30 avril 2014 21:37:57

Not only those 2 folders. When using font software like UTC, suitcaase, FontAgent or other font software fonts can be located anywhere and activated on any place. The font folders you mention are standard Mac OS X folders that can be managed using font book.

If you’re running Mavericks, an ASObjC-based library makes it simple:

use framework "Foundation"

on findFonts()
	return (current application's NSFontManager's sharedFontManager()'s availableFonts()) as list
end findFontFamilies

Thank you all for your feedback, I will use the next code:


tell application "System Events"
	try
		set pathtofonts to "briandonovan:Library:Fonts:MyFont.ttf" as alias
	on error
		beep
	end try
end tell

As simple as this! just by setting the path as alias it will send an error if the font does not exist, nice!!! :smiley:

You don’t need to involve System Events in it – get rid of that tall block.