Error -8068

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

any idea how to fix this?

Brian

Hi,

it’s probably a permission problem.
path to fonts folder refers to /System/Library/Fonts which belongs to the system.

A possible workaround is

do shell script "cp ." with administrator privileges

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.

Actually there are three font folders (system, local and user domain), default is system

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. :slight_smile:

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.

Thank guys!!! so just to be clear! the best solution is to use the user font folder or should i use the do shell script?

Brian

Hello Brian.

Try something like paths to fonts folder from user domain in your original script before resorting to do shell script.

set fontspath to path to fonts folder from user domain as alias

Runs like a charm for me, on an non-administrator account. There is however an undefined x in your script when I run your script with:

set fontspath to path to fonts folder from local domain as alias

as it doesn’t find the fonts there.

DJ pointed it out:

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. *****

Hi Hank.

Your ‘allFonts’ will contain three lists, so ‘thefont is not in allFonts’ will alway be true. It would be better to build ‘allFonts’ by concatenation.

A bit similar thread to this

If this thread if an follow up, then the -8068 error could also be an network permission problem.

Thank you for the script works perfect!

Brian

By the way: Consider also Font Book.app

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