MountVolume

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

Introduction

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.

Why even bother with a script that mounts a volume when the simple "mount volume" command is available?

For starters, the "mount volume" command only tries one protocol. If the user wanted to mount a volume using any protocol, this script will do that. This script also does basic error checking and network testing before even trying to mount the volume (thus avoiding possible long delays or machine crashes).


Related Scripts

Here is a list of other scripts that are related or used with this script:
SaveToLog, a script that this script incorporates and uses to maintain a log file.

What the script produces

Mounts a volume over IP or AppleTalk.

A feedback message is shown on the screen letting the user know the script is running.

A log of errors and activity is also created and updated.

Required modifications to the script

For this script to run properly, you will need to modify it for your computer setup.

A filename is just the filename that appears on a file. If you click on a file, you can copy the filename text by selecting copy from the Edit menu.

A path is the folder structure that leads to a file or folder. A path begins with the hard disk name and is followed by a colon (":"). Every folder is seperated by a colon (":"). The last item is the file. The path to the Finder application is "<startup disk name>:System Folder:Finder". Because the startup disk name is always different on every machine and because they are often changed, this script finds the startup disk name. Therefore, do not include the startup disk name in any paths for this script.

A variable is a bucket used by the computer to store information. In scripts, variables are given names so that the programmer can tell the computer which bucket is what. In AppleScript, a bucket is "filled" with information with this syntax:
set variableName to "information"
Therefore, to set the variables for this script, just find the "set" command for the approprate variable and change the value within the quotes to the information needed for the following:
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 AppleTalk name of the server. Set to "" if AppleTalk connecting is not desired. (i.e. "Mac PD Server")

set ATZoneName to ""

-- the AppleTalk 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 ""

-- Required for any connecting. (i.e. "Public Software")

set user to ""

-- Username, required for any connecting. (i.e. "Guest")

set pass to ""

-- Password, required for any connecting.

set pathToLog to ""
The pathToLog variable should be set to the path to a text file that serves as a log for this script, something something like: ":System Folder:Maintainance:Log". Set the variable to "" if no log is desired. The script will create the file if it doesn't exist and set it to be a BBEdit document.

How to run

To run this script, you need to understand what a function is and what parameters are. A function begins with an "on" statement and ends with an "end" statement. The name of the function follows the "on" and "end" statements. The parameters follow the function name that appears after the "on" statement. For example:
on function1(parameter1, parameter2)
 -- do something
end function1
As the script runs and reaches this code, it will not be executed. Rather, it is skipped! This code will NOT be executed until it is told to be executed with a "function call", a.k.a. "handle call," a.k.a. "sub-routine call", a.k.a. ect.,. Either, the "call" looks like this:
function1("asdf", "adsf")
or,
set tempy to function1(123, jrele)
In fact, it can look like alot of things, but the important thing is that the name of the function is followed by parenthesis that include the necisary parameters. AND it does not begin with "on".

Now, this script will probably be used in another script. To use it in another script, copy the contents of the script file (from the Script Editor), paste it at the bottom of the script you want to mount a volume in. You will then need to "call" it somewhere else in the script. If you look at the original "MountVolume" script, you will notice there is a function "call" at the top. It looks like this:
mountServer(DNSServerName, IPServerAddress, ATServerName, ATZoneName, volumeName, user, pass, pathToLog)
The variables (storage buckets) are set right before the "call". They don't need to be, but it is easier (in this case) to make changes that way.

After you have copied the script, you will want to move the variable settings and the function call to the location in your script that you want to mount the volume.

One important note is that you do not want to include this function call within a "tell" block (the block is everything between the "tell" and "end tell". This results in an error (not sure why or if it should, but it is a bad practice anyway). Do not put the mountVolume() call in a "tell" block.

If you notice, the difference between this function call and original "mount volume" function call is that there is a space between "mount" and "volume" and there is not one in the other "mountVolume". They also take very different parameters. Be sure not to mix them up!

Or, if you know you could just use this script as a library. Eliminate the variable settings and function call. Then include the file and call it that way.

Or, if you just want this script to mount a volume and do nothing else, just change the variables to the appropriate values. Save it as an "Application" or "Classic Applet" with no startup window and then put it wherever you need it (desktop, in the startup items folder, or have it activated with something like Cron).

How this script works

This script is essentially a "black box". That is, you only need to know what to put in and what comes out (which is discussed above).

However, if you have a dying urge to know more, comments have been included in the file, and here is a brief discription:
The script begins by setting the variables that will be used in the function call. It calls the mountVolume function.

The mountVolume function sets a timeout variable. It then checks the network. If it gets an error, the function exits (and the script if used as a stand alone).

It then checks to see if DNS server name was specified. If it was, then it tries to mount the volume over DNS. If there is an error (if the server doesn't mount) then it tries to get the error number and saves the error number and message to a log. If there is no error, the function ends (and the script if used as a stand alone).

If the script did not mount the volume using DNS, it repeats the same process as above but using an IP number instead of DNS address.

If the script did not mount the volume using IP, it repeats the same process as above but tries AppleTalk.

If the script did not mount the volume over AppleTalk, the function exits (and the script if used as a stand alone).
View a flowchart of the script:

Flowchart page 1 – GIF-File, 6.4 KB
Flowchart page 2 – GIF-File, 8.4 KB
Flowchart page 3 – GIF-File, 8.4 KB
Flowchart page 4 – GIF-File, 8.1 KB

Download the script