(* ------------------------------------------------------------------------------------------------------------------------------------ run RR 1.0.5 Written by James Reynolds, 11.30.2000, University of Utah, ACLIS LABS. Last modified 7.3.2001 This script mounts a server volume(s) (over IP preferably) and runs RevRdist. It also displays user feedback. For online documentation, see: http://www.macos.utah.edu/. Select "documentation". Select "Applescript". Select "RevRdist". Or read the read me. History: 12.22.2000 disabled a line that turned file sharing off because sometimes it would crash the computer. 2.5.2001 added new version of SaveToLog (see bottom of script). 4.?.01 Added maintenance pic background. 6.3.2001 moved the maintenance pic code around. General clean up. 6.4.2001 added new version of SaveToLog (see bottom of script). 6.5.2001 removed code to turn file sharing off. Why was it there to begin with? 6.6.2001 added code to quit Crond if the servers don't mount. If you don't use Crond, it won't matter. If you do, this is to make sure that Crond doesn't endlessly call this script (assuming that is what is going on). 7.3.2001 added code to duplicate origianl desktop picture prefs so that if revrdist doesn't copy new prefs, the original picture will return anyway. (This worked in development, but not in deployment. soo...) ------------------------------------------------------------------------------------------------------------------------------------ *) -- Command that calls the function/subroutine/handler runRR() on runRR() -- SET THESE VARIABLES *********************************** -- RevRdist location set pathToDefaultRevRdistFile to ":System Folder:RevRdist" -- the path to the default RevRdist application. (example: ":System Folder:RevRdist") set pathToDefaultRevRdistPrefsFile to ":System Folder:RevRdist Prefs" -- the path to the default RevRdist preferences. (example: ":System Folder:RevRdist Prefs") set pathToAlternateRevRdistFile to ":System Folder:Preferences:Cron Preferences:RevRdist" -- the path to the alternate RevRdist application. (example: ":System Folder:Preferences:RevRdist") set pathToAlternateRevRdistPrefsFile to ":System Folder:Preferences:Cron Preferences:RevRdist Prefs" -- the path to the alternate RevRdist preferences. (example: ":System Folder:Preferences:RevRdist Prefs") --Mount Volume settings VARIABLES FOR MMC Server *********************************** set numberOfServersToMount to 2 -- numberOf servers to mount. Be sure that the number of items (each item is a set of quotes followed by a comma: {"", "", ""} = 3, or {""} = 1, etc.) match this. set DNSServerName to {"revrdist.mlmc.utah.edu", "revrdist.mlmc.utah.edu"} -- the DNS name of the server. Set to "" if DNS connecting is not desired. (example: "macpd.cc.utah.edu") set ipOfVolume to {"128.110.27.2", "128.110.27.2"} -- the IP of the server. Set to "" if IP connecting is not desired. (example: "128.110.56.121") set appleTalkServer to {"MMC RevRdist Server", "MMC RevRdist Server"} -- the AT name of the server. Set to "" if AppleTalk connecting is not desired. (example: "Mac PD Server") set appleTalkZone to {"MLMC", "MLMC"} -- the AT Zone the server is in. Set to "" if AppleTalk connecting is not desired. Required for AT connecting. (example: "UUCC Student Labs") set imageVolumeName to {"MMC RevRdist", "MMC RevRdist #2"} -- Required for any connecting. (example: "Public Software") set userName to {"revrdist", "revrdist"} -- Required for any connecting. (example: "Guest") set passwd to {"", ""} -- Required for any connecting. set pathTomaintenancePic to "" -- path to the maintenance background picture file. Set to "" if not desired. (example: ":System Folder:Appearance:Desktop Pictures:Maintenance.jpg") If you use this, your image must have a specified background image or the maintenance picture will be there after RevRdist is done. set pathsToIdleScripts to {"", ""} -- path to the idle scripts. Set to "" if not desired. (example: ":System Folder:Scripts:Idle Script") set pathToLog to "" -- path to the log file. Set to "" if not desired. (example: ":System Folder:Preferences:AppleScript Log") (* ------------------------------------------------------------------------------------------------------------------------------------ Ignore the rest of this! This is the script starting to do stuff ------------------------------------------------------------------------------------------------------------------------------------ *) -- Display user feedback try set gNotification to post notification "WARNING - RUNNING MAINTENANCE SOFTWARE" & return & return & "This procedure can take up to 15 minutes." & return & "If you cannot wait, move to another computer." & return & return & "PLEASE DO NOT RESTART THIS COMPUTER!!!" playing sound "Temple" end try -- Save to log saveToLogRunRR(pathToLog, "INFO - Starting Script Run RevRdist.") -- Add startup disk name to paths. tell application "Finder" set startupDiskName to (name of startup disk) end tell set pathToDefaultRevRdistFile to startupDiskName & pathToDefaultRevRdistFile set pathToDefaultRevRdistPrefsFile to startupDiskName & pathToDefaultRevRdistPrefsFile set pathToAlternateRevRdistFile to startupDiskName & pathToAlternateRevRdistFile set pathToAlternateRevRdistPrefsFile to startupDiskName & pathToAlternateRevRdistPrefsFile -- Check to see where RevRdist is and try to run it there. if (filesExist(pathToDefaultRevRdistFile, pathToDefaultRevRdistPrefsFile)) then set revRdistLocation to "default" else saveToLogRunRR(pathToLog, "ERROR - RevRdist missing from default location") if (filesExist(pathToAlternateRevRdistFile, pathToAlternateRevRdistPrefsFile)) then set revRdistLocation to "alternate" else set revRdistLocation to "error" saveToLogRunRR(pathToLog, "ERROR - RevRdist missing from alternate location") end if end if if (revRdistLocation is "error") then saveToLogRunRR(pathToLog, "ERROR - Can not run RevRdist!") else -- Mount the server repeat with i from 1 to numberOfServersToMount set networkTimeOut to 10 set mountStatus to mountServer(item i of DNSServerName, item i of ipOfVolume, item i of appleTalkServer, item i of appleTalkZone, item i of imageVolumeName, item i of userName, item i of passwd, networkTimeOut, pathToLog) if (mountStatus is not "IP" and mountStatus is not "DNS" and mountStatus is not "AT") then exit repeat end if end repeat -- If the servers mounted then proceed. if (mountStatus is "IP" or mountStatus is "DNS" or mountStatus is "AT") then saveToLogRunRR(pathToLog, "INFO - Mounted volumes over " & mountStatus & ".") (* ------------------------------------------------------------------------------------------------------------------------------------ If the volumes mount, do the following! ------------------------------------------------------------------------------------------------------------------------------------ *) if (pathTomaintenancePic is not equal to "") then --Duplicated Desktop Picture Prefs. try tell application "Finder" if (file "Desktop Pictures Prefs copy" of preferences folder exists) then delete file "Desktop Pictures Prefs copy" of preferences folder end if duplicate file "Desktop Pictures Prefs" of preferences folder to preferences folder with replacing if (file "Desktop Pictures Prefs Bkup" of preferences folder exists) then delete file "Desktop Pictures Prefs Bkup" of preferences folder end if set name of file "Desktop Pictures Prefs copy" of preferences folder to "Desktop Pictures Prefs Bkup" as string end tell saveToLogRunRR(pathToLog, "INFO - Duplicated Desktop Picture Prefs.") on error mes saveToLogRunRR(pathToLog, "ERROR - Duplicated Desktop Picture Prefs error:" & mes) end try --Sets the desktop picture to a JPG that reads "This Mac is running Maintenance software, please wait", etc. try set iute to startupDiskName & pathTomaintenancePic as string tell application "Appearance" launch set picture file of monitor 1 to file iute set picture positioning of monitor 1 to automatic quit end tell saveToLogRunRR(pathToLog, "INFO - Put up Maintenance background picture.") on error mes saveToLogRunRR(pathToLog, "ERROR - Maintenance background picture error:" & mes) end try --Delete Desktop Picture Prefs and replace it with the original. try tell application "Finder" deleteFile file "Desktop Pictures Prefs" of preferences folder set name of file "Desktop Pictures Prefs Bkup" of preferences folder to "Desktop Pictures Prefs" as string end tell saveToLogRunRR(pathToLog, "INFO - Deleted Desktop Picture Prefs and replaced with original.") on error mes saveToLogRunRR(pathToLog, "ERROR - Delete Desktop Picture Prefs error:" & mes) end try end if --Delete any idle scripts (so that they don't startup the Finder while RevRdist is running. try set deletedScript to false repeat with i in pathsToIdleScripts set iut to (startupDiskName & i as string) tell application "Finder" if (file iut exists) then try delete file iut set deletedScript to true exit repeat end try end if end tell end repeat if deletedScript is true then saveToLogRunRR(pathToLog, "INFO - Deleted Idle script: " & iut) else saveToLogRunRR(pathToLog, "INFO - No Idle script found to delete.") end if on error mes saveToLogRunRR(pathToLog, "ERROR - Tried to delete idle script but got: " & mes) end try -- Quit processes that RevRdist doesn't catch normally. -- quit Print Monitor, coming soon... try tell application "Finder" set the_process to every process whose file type is not "FNDR" set the_process to the_process as list set the_count to number of items in the_process end tell on error mes saveToLogRunRR(pathToLog, "ERROR - Quiting apps error:" & mes) end try --if the_count > 1 then -- repeat with the_app in the_process -- my KillIt(the_app) -- end repeat --else -- just one process is running so quit it -- my KillIt(the_app) --end if -- Run application RevRdist saveToLogRunRR(pathToLog, "INFO - Starting up RevRdist application at " & revRdistLocation & " location.") try with timeout of 5 seconds if (revRdistLocation is "default") then tell application "Finder" open file pathToDefaultRevRdistFile end tell else if (revRdistLocation is "alternate") then tell application "Finder" open filepathToAlternateRevRdistFile end tell end if end timeout on error mes saveToLogRunRR(pathToLog, "ERROR - Tried to start RevRdist but got: " & mes) end try else saveToLogRunRR(pathToLog, "INFO - Volumes did not mount.") -- Volumes could not mount. Quit Crond try tell application "Finder" set quitme to (name of process 1 whose creator type is "MmCr") tell me to tell application quitme to quit without saving end tell saveToLogRunRR(pathToLog, "INFO - Quit Crond.") end try -- put away all disks repeat with i from 1 to numberOfServersToMount try --put away (item i of imageVolumeName) end try end repeat saveToLogRunRR(pathToLog, "INFO - Quiting") end if end if end runRR --The following script displays a user feedback message and requires the Scripting Addition "Appearance OSAX" on displayMessage(messageText, alertSound) try if (alertSound is not equal to "") then set gNotification to notification messageText else set gNotification to notification messageText --given alertSound end if end try end displayMessage -- This handle checks to see if files exist (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 filesExist(path1, path2) tell application "Finder" if (the file path1 exists) and (the file path2 exists) is true then set returnValue to true else set returnValue to false end if end tell return returnValue end filesExist (* ------------------------------------------------------------------------------------------------------------------------------------ mountVolume 1.0 Written by James Reynolds, 12.19.2000, University of Utah, ACLIS LABS The purpose of this script is to help users with other scripts that need to mount volumes. It is also useful for the user to just plain mount a volume. For online documentation, see: http://www.macos.utah.edu/. Select "documentation". Select "Applescript". Select "MountVolume". Or read the read me. ------------------------------------------------------------------------------------------------------------------------------------ *) -- Modify the below paramaters to match your particular network setup. -- Parameters: set DNSServerName to "" -- the DNS name of the server. Set to "" if DNS connecting is not desired. (example: "macpd.cc.utah.edu") set IPServerAddress to "" -- the IP of the server. Set to "" if IP connecting is not desired. (example: "128.110.56.121") set ATServerName to "" -- the AT name of the server. Set to "" if AppleTalk connecting is not desired. (example: "Mac PD Server") set ATZoneName to "" -- the AT Zone the server is in. Set to "" if AppleTalk connecting is not desired. Required for AT connecting. (example: "UUCC Student Labs") set volumeName to "MMC RevRdist" -- Required for any connecting. (example: "Public Software") set user to "" -- Required for any connecting. (example: "Guest") set pass to "" -- Required for any connecting. set NetworkTimeoutInSeconds to 10 -- the time out for each check. set pathToLog to "" -- path to the log file. Set to "" if not desired. (example: ":System Folder:Preferences:AppleScript Log) -- Command that calls the function/subroutine/handler mountServer(DNSServerName, IPServerAddress, ATServerName, ATZoneName, volumeName, user, pass, NetworkTimeoutInSeconds, pathToLog) (* ------------------------------------------------------------------------------------------------------------------------------------ The following is the "black box" *) -- This function/subroutine/handler checks to see if a parameter (example: DNSServerName, IPServeAddress, or ATServerName) is present -- and then runs the appropriate statment. on mountServer(DNSServerName, IPServerAddress, ATServerName, ATZoneName, volumeName, user, pass, NetworkTimeoutInSeconds, pathToLog) -- Save to log saveToLogMountServer(pathToLog, "INFO - Starting the script MountVolume.") -- Show message box for user feedback. try set sNotification to post notification "Please wait while I try to mount a volume..." end try -- Check the network set networkStatus to checkNetwork() if (networkStatus is false) then return false end if --Try mounting the server volume set volumeStatus to "False" if (DNSServerName is not equal to "") then with timeout of NetworkTimeoutInSeconds seconds try set userPassword to getUserPassword(user, pass) mount volume userPassword & DNSServerName & "/" & volumeName saveToLogMountServer(pathToLog, "INFO - Server mounted using host name:" & DNSServerName) set volumeStatus to "DNS" on error errorText number errorNum -- something may have gone wrong if (errorNum is -5062) then set volumeStatus to "Volume already mounted." else errorMountingServer(errorText, errorNum, DNSServerName & "/" & volumeName, pathToLog) end if end try end timeout end if if (IPServerAddress is not equal to "" and volumeStatus is equal to "False") then with timeout of NetworkTimeoutInSeconds seconds try set userPassword to getUserPassword(user, pass) mount volume userPassword & IPServerAddress & "/" & volumeName saveToLogMountServer(pathToLog, "INFO - Server mounted using IP address: " & IPServerAddress) set volumeStatus to "IP" on error errorText number errorNum -- something may have gone wrong if (errorNum is -5062) then set volumeStatus to "Volume already mounted." else errorMountingServer(errorText, errorNum, IPServerAddress & "/" & volumeName, pathToLog) end if end try end timeout end if if (ATServerName is not equal to "" and volumeStatus is equal to "False") then with timeout of NetworkTimeoutInSeconds seconds try mount volume volumeName on server ATServerName in AppleTalk zone ATZoneName as user name user with password pass saveToLogMountServer(pathToLog, "INFO - Server mounted using AppleTalk:" & ATServerName) set volumeStatus to "AT" on error errorText number errorNum -- something may have gone wrong if (errorNum is -5062) then set volumeStatus to "Volume already mounted." else errorMountingServer(errorText, errorNum, ATZoneName & "/" & ATServerName & "/" & volumeName, pathToLog) end if end try end timeout end if -- remove initial message box try remove notification sNotification end try return volumeStatus end mountServer -- This subroutine/handler processes errors on errorMountingServer(errorText, errorNum, serverAddress, pathToLog) if errorNum is not -5062 then -- error -5062 = volume already mounted saveToLogMountServer(pathToLog, "ERROR - " & errorNum & " " & getError(errorNum) & " Address:" & serverAddress & ": " & errorText) -- look up error msg and log it return false -- there was a problem else return true -- error is -5062 ... nothing wrong end if end errorMountingServer -- This subroutine/handler does a error code lookup on getError(errorNum) -- error code lookup if (errorNum is -5062) then return "Volume already mounted." else if (errorNum is -5019) then return "Incorrect parameter." else if (errorNum is -5023) then return "Incorrect username or password." else if (errorNum is -5016) then return "Network/Server is unavailable." else if (errorNum is -35) then return "Server volume unknown." else if (errorNum is -23045) then return "Network/Server is unavailable." else if (errorNum is -50) then return "No password specified." end if return (("Error #" & errorNum as text) & " occurred.") end getError on checkNetwork() -- This handle is very basic at this point and will be further developed in the future. try -- First check to see if AT is on. tell application "Finder" if (computer "atlk") is 0 then return false end if end tell return true on error return false end try end checkNetwork on getUserPassword(user, pass) set userPassword to "afp://" if (user is not equal to "") then set userPassword to userPassword & user if (pass is not equal to "") then set userPassword to userPassword & ":" & pass end if set userPassword to userPassword & "@" end if return userPassword end getUserPassword on saveToLogMountServer(pathToLog, theMessage) saveToLogRunRR(pathToLog, theMessage) end saveToLogMountServer (* ------------------------------------------------------------------------------------------------------------------------------------ SaveToLog 1.0.2 (5.31.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 script now saves all new messages at the top of the log file. 5.31.2001 script now truncates the log file if it is too big (variables that sets the size: MaxNumberOfLinesInLogFile and MaxSizeOfLogFile) ------------------------------------------------------------------------------------------------------------------------------------ *) (*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 saveToLogRunRR(pathToLog, theMessage) if (pathToLog is not equal to "") then try -- Application Settings: set MaxNumberOfLinesInLogFile to 1000 -- This allows for 50 characters a line (characters per line = MaxSizeOfLogFile/MaxNumberOfLinesInLogFile) set MaxSizeOfLogFile to 50000 --If the file is too big, this script will run out of memory... if the file is bigger than this, instead of truncating it, I am just deleting it. I made code to truncate it using the MaxNumberOfLinesInLogFile. -- Complete the paths. tell application "Finder" set startupDiskName to (name of startup disk) end tell set pathToLog to startupDiskName & pathToLog -- The message set theMessage2 to theMessage & " - " & ((current date) as string) & return -- Check to make sure the file exists and isn't too big... tell application "Finder" if (file pathToLog exists) then set fileSize to size of file pathToLog --display dialog fileSize if (fileSize is greater than MaxSizeOfLogFile) then delete file pathToLog set theMessage2 to theMessage2 & "INFO - Deleted log file because it was bigger than " & MaxSizeOfLogFile & " bytes." & return & theMessage2 end if else set fileSize to 0 end if end tell -- Open and read the file set fileReference to (open for access file pathToLog with write permission) if (fileSize is greater than 0) then set fileContents to read fileReference else set fileContents to "" end if -- Truncate the file if it is too big if ((count of every paragraph of fileContents) is greater than MaxNumberOfLinesInLogFile) then set numberOfParagraphs to count of every paragraph of fileContents set numberOfCharacters to count of every character of fileContents set numberOfCharactersOfLastParagraph to count of every character of paragraph (numberOfParagraphs - 1) of fileContents set numberOfCharactersToKeep to numberOfCharacters - numberOfCharactersOfLastParagraph - 1 set fileContents2 to characters 1 thru numberOfCharactersToKeep of fileContents else set fileContents2 to fileContents end if -- Rewrite and close the file write theMessage2 & fileContents2 to fileReference starting at 1 close access fileReference -- Set the file's creator type to BBEdit try tell application "Finder" set the creator type of the file pathToLog to "R*ch" end tell end try on error mes try close access fileReference end try display dialog mes end try end if end saveToLogRunRR on KillIt(the_app) set the_app to the_app as string if the_app does not contain "Quit the Running Process" then tell application the_app quit end tell end if try activate application "MMC RevRdist:Special Items:Cron Preferences:0-8 3 * * *:System Folder:Preferences:Cron Preferences:RevRdist" end try end KillIt