(* ------------------------------------------------------------------------------------------------------------------------------------ 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. (i.e. "macpd.cc.utah.edu") set IPServerAddress to "" -- the IP of the server. Set to "" if IP connecting is not desired. (i.e. "128.110.56.121") set ATServerName to "" -- the AT name of the server. Set to "" if AppleTalk connecting is not desired. (i.e. "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. (i.e. "UUCC Student Labs") set volumeName to "MMC RevRdist" -- Required for any connecting. (i.e. "Public Software") set user to "" -- Required for any connecting. (i.e. "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. (i.e. ":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 (i.e. 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 -- This subroutine/handler writes errors and info to end of log file on saveToLogMountServer(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 saveToLogMountServer