How can I get Automator to mount a network volume?

Solution 1:

I build automator workflows like this all the time. You only need two actions, and they're both Files & Folders actions.

1) Get Specified Servers. This will let you build a list of shares to connect to. If you can map it from Finder -> Go -> Connect to server, you can use this.

2) Connect to Servers. This will connect to any servers passed to it (either from get specified servers or from ask for servers).

Solution 2:

I use the following applescript to mount directories in conjunction with MarcoPolo so network shares are automatically mounted when I get to both my office and home.

You'll need to change USERNAME, PASSWORD, SERVER/SHARENAME and possibly smb:// depending on your server type.

tell application "Finder"
    try
        mount volume "smb://USERNAME:PASSWORD@SERVER/SHARENAME"
        delay 1
    end try
end tell

UPDATE: An option without MarcoPolo: You can ping the server first and only try to connect if you get a response. You can then add this script into your Login Items

(Let's say you are trying to connect to a server named "some_server")

-- (0) Check to see if there server exists by pinging it
set max_retry to 60
set k to 0
repeat while (do shell script "ping -c 1 some_server") contains "100% packet loss"
    delay 5
    set k to k + 1
    if k > max_retry then error "Server is not responding for predefined period." number 8000
end repeat

-- (1) It exists, mount the volume
tell application "Finder"
    try
        mount volume "smb://USERNAME:PASSWORD@some_server/SHARENAME"
        delay 1  --Optional, was added due to slow network issues
    end try
end tell