Thanks to help from StefanK I solved a problem installing fonts automatically, however my method does not handle outline fonts.
Stefan included a shell script routine to install the fonts but I had trouble getting it to work, I’ve tried modifying it to move a single font, but me knowing nothing of shell scripting, it crashes.
Would anyone mind advising me of how to write a shell script to move/install an outline font, with replacing if necessary.
TIA
Santa
tell application "Finder"
try
set NewFontInstalled to false
set theFonts to (get files of entire contents of folder holding_folder whose kind contains "font")
if number of items in theFonts > 0 then
try
tell application "Font Book"
activate
delay 6
repeat with aFont in theFonts
if kind of aFont does not contain "outline font" then
open aFont
delay 2
if exists window 1 then
tell application "System Events" to tell process "Font Book"
click button "Install Font" of group 1 of window 1
end tell
end if
delay 2
set NewFontInstalled to true
tell application "Finder"
move aFont to trash
end tell
else
tell application "Finder"
--do shell script "mv -f " & quoted form of POSIX path of aFont & "* /Library/Fonts/"
end tell
end if
end repeat
end tell
on error TheError number errNum
display dialog "SecondAttachmentPrintCycle " & return & "Error number " & errNum & return & TheError as string
end try
end if
if NewFontInstalled then
tell application "Font Book"
quit
end tell
end if
on error TheError number errNum
display dialog "SecondAttachmentPrintCycle " & return & "Error number " & errNum & return & TheError as string
end try
end tell
Model: G5 1.8 GHz
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
try this, I added two things to check the installation location (User or Computer) and to install multiple font styles from one suitcase
set NewFontInstalled to false
tell application "Finder" to set theFonts to (get files of entire contents of folder holding_folder whose kind contains "font")
if (count theFonts) > 0 then
try
tell application "Font Book"
activate
tell application "System Events" to tell process "Font Book"
keystroke "," using command down
repeat until exists window "Font Book Preferences"
delay 0.5
end repeat
tell window "Font Book Preferences" to set installPath to value of pop up button 1 -- check the installation location
delay 0.5
end tell
close window 1
if installPath is "User" then
set installPath to (path to fonts from user domain)
else
set installPath to (path to fonts from local domain)
end if
repeat with aFont in theFonts
if kind of (info for aFont as alias) does not contain "outline font" then
open aFont
repeat until exists window 3
delay 0.5
end repeat
repeat while (count windows) > 2 -- if there are multiple fonts in the suitcase
tell application "System Events" to tell process "Font Book"
click button "Install Font" of group 1 of (get some window whose images is not {})
end tell
end repeat
set NewFontInstalled to true
tell application "Finder" to move aFont to trash
else
do shell script "mv -f " & quoted form of POSIX path of (aFont as alias) & space & quoted form of POSIX path of installPath
end if
end repeat
end tell
on error TheError number errNum
display dialog "SecondAttachmentPrintCycle " & return & "Error number " & errNum & return & TheError as string
end try
if NewFontInstalled then quit application "Font Book"
end if
I think it’s possible to do the Font Book stuff without GUI Scripting, but I’m not yet sure if this is 100% foolproof:
set NewFontInstalled to false
tell application "Finder"
try
set theFonts to (files of entire contents of folder holding_folder whose kind contains "font") as alias list
on error
set theFonts to {(1st file of entire contents of folder holding_folder whose kind contains "font") as alias}
end try
end tell
if (count theFonts) > 0 then
try
tell application "Font Book"
activate
if (name of installation target is "User") then
set installPath to quoted form of POSIX path of (path to fonts from user domain)
else
set installPath to quoted form of POSIX path of (path to fonts from local domain)
end if
set nonOutlineFonts to {}
set trashableFonts to {}
repeat with aFont in theFonts
if (kind of (info for aFont) contains "outline font") then
do shell script "mv -f " & quoted form of POSIX path of (aFont as alias) & space & installPath
else
set end of nonOutlineFonts to (POSIX path of aFont)
set end of trashableFonts to aFont
set NewFontInstalled to true
end if
end repeat
end tell
if (NewFontInstalled) then
tell application "Font Book"
add nonOutlineFonts to installation target
delay (count nonOutlineFonts) * 0.3 -- because 'add' doesn't complete before the script moves on.
quit
end tell
tell application "Finder" to delete trashableFonts
end if
on error TheError number errNum
display dialog "SecondAttachmentPrintCycle " & return & "Error number " & errNum & return & TheError as string
end try
end if
No. It seems only to understand POSIX paths “ which I consider to be bad practice in AppleScript, especially since Font Book’s dictionary doesn’t point out the departure from the norm.