At work we use Quark and Quarkxpress along with Extensis suitcase server to manage fonts, on occasion the fonts will become corrupt and we need to manually delete the font caches and restart the machine
this is what i belive to be perfect work for a script
when i try to do this:
if appIsRunning("Extensis Suitcase X1") then
tell application "Extensis Suitcase X1" to quit
end if
if appIsRunning("QuarkXPress") then
tell application "QuarkXPress" to quit
end if
if appIsRunning("QuarkCopyDesk") then
tell application "QuarkCopyDesk" to quit
end if
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
I get an error on compile that says “Application isn’t Running.”
but only on one of the if statments ( the quarkxpress one)
Secondly i need to delete a number of cache files
tell application "Finder"
-- set myfile to (some path) as alias
delete myfile
end tell
However this being my first applescript im not sure how to assgine myfile to a path
(also is this the best way to delete multiple files?)
Lastly i need to reboot the machine
tell application "Finder"
restart
end tell
Is this the best way to do it?
I would also like to write to a log file somewhere on a network drive but i cant even figure out where to start with that.
Hi,
the following script quits the applications, clears the font cache and logs every step.
It’s sufficient to restart the ATS server, a reboot is not necessary.
The log can be watched in Console.app
The script requires OS 10.5 Leopard
property appList : {"Extensis Suitcase X1", "QuarkXPress", "QuarkCopyDesk"}
property logName : "ClearFontCache.log"
tell application "System Events" to set allProcesses to name of processes
repeat with oneApp in appList
if oneApp is in allProcesses then
quit application oneApp
write_log from oneApp & " quit"
end if
end repeat
do shell script "/usr/bin/atsutil databases -remove"
write_log from result
do shell script "/usr/bin/atsutil server -shutdown"
write_log from result
do shell script "/usr/bin/atsutil server -ping"
write_log from result
on write_log from theMessage
tell (current date) to set timestamp to short date string & space & time string & space
set logFile to ((path to library folder from user domain as text) & "Logs:") & logName
try
set the logStream to open for access file logFile with write permission
set logFileEof to get eof of the logStream
write timestamp & theMessage & return to logStream starting at eof as «class utf8»
close access logStream
on error
try
close access file logFile
end try
end try
end write_log
sorry for the delay but we are only on 10.4.1
what would i need to change to make this 10.4 compliant
without warranty, but this should work in Tiger,
the admin password is required
property appList : {"Extensis Suitcase X1", "QuarkXPress", "QuarkCopyDesk"}
property logName : "ClearFontCache.log"
property PW : "¢¢¢¢¢¢"
tell application "System Events" to set allProcesses to name of processes
repeat with oneApp in appList
if oneApp is in allProcesses then
quit application oneApp
write_log from oneApp & " quit"
end if
end repeat
do shell script "/bin/rm -r /Library/Caches/com.apple.ATS/" password PW with administrator privileges
write_log from "Font cache deleted and rebooted"
do shell script "shutdown -r now" password PW with administrator privileges
on write_log from theMessage
tell (current date) to set timestamp to short date string & space & time string & space
set logFile to ((path to library folder from user domain as text) & "Logs:") & logName
try
set the logStream to open for access file logFile with write permission
set logFileEof to get eof of the logStream
write timestamp & theMessage & return to logStream starting at eof as «class utf8»
close access logStream
on error
try
close access file logFile
end try
end try
end write_log