SaveToLog

By: James Reynolds - Revised: 2006-06-08 devin

Introduction

A machine log can be kept that records various user actions, or system restarts.

Note: if this log is in a lab enviroment that has hard disk imaging software like RevRdist or Assimilator, the log file will need to be ignored for it to serve any good.

Note # 2: this script will be updated to do the following asap:
  1. Put all new entries at the top instead of the bottom.
  2. Keep the log size under 32 or 64 k.
  3. A better description of what this script does will also accompany the update.

The Script, version 1.0.1

(* -----------------------------------------------------------------
saveToLog 1.0.1 (2.5.2001)
Written by James Reynolds, 12.18.2000, University of Utah, ACLIS LABS
The purpose of this script is to save messages to a log file.
For online documentation, see: http://www.macos.utah.edu/. Select "documentation". Select "Applescript".
Select "Save To Log".
Or read the read me.
History: 2.5.2001 Changed the script to save all messages at the top of the log file.
---------------------------------------------------------------------*)

(*This handle saves a message to a log. The date is saved after the message. The log is set to BBEdit's creator type.*)

on saveToLog(pathToLog, theMessage)
     if (pathToLog is not equal to "") then
          try
               -- Complete the paths.
               tell application "Finder"
                    set startupDiskName to (name of startup disk)
               end tell
               set pathToLog to startupDiskName & pathToLog
               set fileReference to (open for access file pathToLog ¬
                    with write permission)
               set fileContents to read fileReference
               write theMessage & " - " & ((current date) as string) ¬
                    & return & fileContents &      return to ¬
                    fileReference starting at 1
               close access fileReference
               tell application "Finder"
                    set the creator type of the file pathToLog ¬
                         to "R*ch"
               end tell
          on error mes
               try
                    close access fileReference
               end try
          end try
     end if
end saveToLog