(* ------------------------------------------------------------------------------------------------------------------------------------ RevRstatus 1.0 Written by James Reynolds, 11.30.2000, University of Utah, ACLIS LABS The purpose of this script is to help lab administrators quickly and easily see exactly when RevRdist ran last. For online documentation, see: http://www.macos.utah.edu/. Select "documentation". Select "Applescript". Select "RevRdist Status". Or read the read me. ------------------------------------------------------------------------------------------------------------------------------------ *) -- SET THESE VARIABLES *********************************** set nameOfDefaultStatusFile to "RevRdist Status Template" -- the name of the file to be renamed and moved to the desktop. set pathToDefaultStatusFile to ":System Folder:" -- the path of the file to be renamed and moved to the desktop (WITHOUT the disk name, i.e., the startup disk name is added in the handle; with a beginning ":" and an end ":"). set pathToLog to ":System Folder:Preferences:Machine Log" -- path to the log file. Set to "" if not desired (WITHOUT the disk name, i.e., the startup disk name is added in the handle). -- -- The following line runs the script. Comment it out if you want to call the function putRevRstatusOnDesktop() someother way. putRevRstatusOnDesktop(nameOfDefaultStatusFile, pathToDefaultStatusFile, pathToLog) (* ------------------------------------------------------------------------------------------------------------------------------------ The following is the "black box" *) on putRevRstatusOnDesktop(nameOfDefaultStatusFile, pathToDefaultStatusFile, pathToLog) -- Complete the paths. tell application "Finder" set startupDiskName to (name of startup disk) end tell set pathToDefaultStatusFile to startupDiskName & pathToDefaultStatusFile set pathAndNameOfDefaultStatusFile to pathToDefaultStatusFile & nameOfDefaultStatusFile -- Save to log saveToLogStatus(pathToLog, "INFO - Starting the script RevRstatus.") -- Get the screen size try set sl to screen list -- Jon's Commands set resolution to screen size of item 1 of sl set width to (item 1 of resolution as number) set height to (item 2 of resolution as number) on error saveToLogStatus(pathToLog, "ERROR - Jon's commands failed.") set width to -1 set height to -1 end try -- Show message box for user feedback. try set gNotification to post notification "Finding status of RevRdist..." end try -- Check to see if the right files exist. Save to log any missing files. -- If the default status file and the the "RevRdist log" exist, then the date is extracted and the file is placed on the desktop. -- If the default status file exists but the "RevRdist log" is missing, then a message is put on the desktop that says so. -- If the default status file is missing but the "RevRdist log" exists, then a dialog box (requires Appearance OSAX Scripting Addition) is placed on the desktop saying when RevRdist last ran. -- If the default status file and the the "RevRdist log" are missing, then a dialog box (requires Appearance OSAX Scripting Addition) is placed on the desktop saying that both files are missing. if (fileExists(startupDiskName & ":System Folder:Preferences:RevRdist log")) then tell application "Finder" set the_date to the modification date of the file "RevRdist log" of preferences folder end tell -- //////////////////////////////////////////////////////////// -- Set name of the Status file here! - Must be 31 or less characters. -- Get the month as a number set month_name to get the month of the_date set the list_of_months to {January, February, March, April  , May, June, July, August, September, October, November, December} repeat with i from 1 to 12 if item i of the list_of_months is the month_name then set the numeric_month to i exit repeat end if end repeat -- Get the day set the text_day_temp to characters 1 thru 3 of (get the weekday of the_date as string) set the text_day to (((item 1 of text_day_temp) as string) & (item 2 of text_day_temp) as string) & (item 3 of text_day_temp) as string set the numeric_day to get the day of the_date -- Get the time and get rid of the colons (because they are used for paths and thus will not work in a filename!) set the numeric_time to get the time string of the_date as string set old_delimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set theHour to the first text item of numeric_time set theMins to the second text item of numeric_time set AppleScript's text item delimiters to " " set theRest to the second text item of numeric_time set AppleScript's text item delimiters to old_delimiters set numeric_time to theHour & "." & theMins & " " & theRest -- Create the file name set newFileName to "RR Ran " & text_day & " " & numeric_month & "/" & numeric_day & " at " & numeric_time -- //////////////////////////////////////////////////////////// else saveToLogStatus(pathToLog, "ERROR - RevRdist Log is missing") -- //////////////////////////////////////////////////////////// -- Set name of the Status file here! - Must be 31 or less characters. set newFileName to "¥ERROR-RevRdist Log is missing!" -- //////////////////////////////////////////////////////////// end if if (fileExists(pathAndNameOfDefaultStatusFile)) then try set newFile to startupDiskName & ":Desktop Folder:" & newFileName if (fileExists(newFile) is false) then tell application "Finder" set tempFile to duplicate the file pathAndNameOfDefaultStatusFile set tempFile2 to tempFile as string set the name of the file tempFile2 to newFileName as string set newFile to pathToDefaultStatusFile & newFileName move the file newFile to desktop set locked of file newFileName of desktop to true end tell end if on error mes saveToLogStatus(pathToLog, "ERROR - Error trying to make the RevRdist status file: " & mes) end try try if (width is not equal to -1 or height is not equal to -1) then tell application "Finder" set position of file newFileName of desktop to {width - 104, height - 46} end tell else saveToLogStatus(pathToLog, "ERROR - Can not place RevRdist Status file because Jon's commands returned an error!") end if on error mes saveToLogStatus(pathToLog, "ERROR - Error trying to place the RevRdist status file: " & mes) end try else saveToLogStatus(pathToLog, "ERROR - Default RevRdist Status file is missing!") try -- disable the next line if this type of message is desired -- set sNotification to post notification newFileName end try end if -- remove initial message box try remove notification gNotification end try end putRevRstatusOnDesktop -- This handle checks to see if a file exists (based on a path which is in string format, not alias). -- This is split to a handle to avoid various errors and complex code that occurs otherwise. on fileExists(fileToCheck) tell application "Finder" if (the file fileToCheck exists) then return true else return false end if end tell end fileExists -- 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 saveToLogStatus(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 lineNumber to get eof of fileReference write theMessage & " - " & ((current date) as string) & return & return to fileReference starting at lineNumber close access fileReference tell application "Finder" set the creator type of the file (pathToAppleScriptLog of globalVariables) to "R*ch" end tell end try end if end saveToLogStatus