Hi, hope someone can help with this problem. I developed a Script taht checks for a Font in the font folder, if font is not installed. Te script copies the font into the font folder.
set x to path to me
set Fonts_to_check to {"Font1.ttf", "Font2.ttf"}
repeat with i from 1 to count of Fonts_to_check
set thefont to item i of Fonts_to_check
tell application "Finder"
set fontspath to path to the fonts folder as alias
set fontspathfull to fontspath & thefont as text
log fontspath
log fontspathfull
if exists file fontspathfull then
-- we do nothing!
else
-- we put file in folder
set thepath to x & "Contents:Resources:fonts:" & thefont as text
log thepath
duplicate file thepath to fontspath with replacing
end if
end tell
end repeat
This works fine, but I tested the applescript in a different computer and I get error -8068
There are two font folders, you can specify which with either from user domain, (to your local with no rights problem) or from local domain, which is the one that is default, and you have currently gotten at.
It can be interesting to have a look in your personal fonts folder, but my bet is that most of it is in the System Fonts folder, I am not sure of the consequences of moving them, but personally I’d abstain from that.
I’m sorry for the slip, I didn’t check it, I was sure there were only two of that one, knowing three is the default, and what’s worse, that the non-mentioned was the default one!
Now I must recollect what there was just two of.
Edit
path to temporary items has both local domain and system domain, but the folder is shared.
Still it’s definitely not recommended (also by Apple) to use the System’s Font folder. Here are fonts stored that belongs to the root user (which you are not). Therefore store fonts in the local domain if you want to install them for every user or install them in the user domain when you want it only install for the current user.
To install fonts only for the current user, use user domain (no further privileges required).
To install fonts for all users, use local domain (at least admin privileges required).
Do not use system domain
Agree with the above advice. Install fonts in the user or local fonts folder. Here’s some code to 1) get the names of all the fonts installed in those 3 fonts folders and 2) install your font in the users fonts folder if it isn’t already in one of the folders…
***** Script removed due to a mistake. Please see post #15 for the correct script. *****
Nigel is right. I made a silly mistake. You must change the allFonts section to concatenate the lists rather than setting the end. So please use this script…
set Fonts_to_check to {"Font1.ttf", "Font2.ttf"}
set myFontsPath to (path to me as text) & "Contents:Resources:fonts:"
-- the fonts folders
set systemFontsFolder to path to fonts folder from system domain
set localFontsFolder to path to fonts folder from local domain
set userFontsFolder to path to fonts folder from user domain
-- get the names of all the fonts on your system
tell application "Finder"
set allFonts to name of files of systemFontsFolder & name of files of localFontsFolder & name of files of userFontsFolder
end tell
-- install them in the user folder if necessary
repeat with i from 1 to count of Fonts_to_check
set thefont to item i of Fonts_to_check
if thefont is not in allFonts then
set thepath to myFontsPath & thefont
tell application "Finder" to duplicate file thepath to userFontsFolder
end if
end repeat