Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript : install a font

Hello

I'm a french user, very novice in scripting. In an application I created, a special font is required. So I wrote an applescript to install it in the FontBook. This is my code :


-- Chemin d'accès du présent script

set theScriptPath to path to me


-- chemin du dossier actuel

tell application "Finder"

set my_folder_path to container of (path to me) as text

-- Chemin d'accès à la police

set theFontPath to my_folder_path & "IDAutomationHC39M.ttf"

end tell


set theFont to theFontPath


-- installation police

tell application "Finder"

open theFontPath

end tell


tell application "Font Book"

if installation target is not font domain "User" then

set installation target to font domain "User"

end if

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 "Installer la police"

end tell

end tell

tell application "Font Book" to quit

end tell

end tell

It's certainly not very pure, but it runs ! The only problem is when the font already exists for user or system, an alert appears to warn of the existence of a doubloon. How can I include a test : if the font exists do nothing else install the font ?

Thanks for your help

Noël

G4 1,25, Mac OS X (10.4.3)

Posted on Jun 4, 2012 8:50 AM

Reply
7 replies

Jun 4, 2012 11:59 PM in response to BDAqua

Ok ! I understand... I tried the following adaptation of the script above



set msg to "no"


tell application "Finder"

if exists POSIX file "~/Library/Fonts/IDAutomationHC39M.ttf" then

set msg to "yes"

end if

end tel

Font present or not I get the following answer and nothing in the result


tell application "Finder"

exists file ":~:Library:Fonts:IDAutomationHC39M.ttf"

--> false

end tell

I told in the first message I was novice++++ Don't be angry ! 😉

Noël

Jun 5, 2012 11:05 AM in response to ndubau

No expert here either, looks like Apple Script doesn't like the home folder shortcut of "`" as it cahanges it to...


exists file ":~:Library:Fonts:IDAutomationHC39M.ttf"


And no idea if that is the same, doesn't appear to be.


Only thing I've worked out so far is how to really get the Home folder...


setmyPathto(path tohome folder)asstring

display dialog "myPath is " & myPath

Applescript : install a font

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.