If you want to connect to server every time you logon, is very simple in Mac. We can utilize Apple Script to do the magic. In this tutorial is using example from my previous post, Share Folder in Ubuntu 11.04 for Mac OSX Lion, how to mount Time Machine disk in Ubuntu server.
Applescript is very useful and simple tool available in Mac OSX that can help us to do whatever we want.
Create the script
The logic for this task is first to check if the volume is exist, if not then the share server is not connected so tell Mac to connect to server. Second is add it to Login Items List to run it automatically.
Open the AppleScript Editor. From Finder open
Applications - Utilities - AppleScript Editor. Then copy and paste the following code.
tell application "Finder"
if not (disk "TimeMachine" exists) then
mount volume "afp://username:email@example.com/TimeMachine"
password as whatever you have created in your server. You can also add more disks to the script for example mount share disk, DVD, etc. if you like.
Save it to whatever you want, for example
Let’s do the testing. Make sure you are not connected to the server. Disconnect it or unmount the disk from Finder if you are connected. Go back to AppleScript Editor, click
Compile button. If you see no error then click
Run button. You should see
file: "TimeMachine" at the Result pane. Check from
Finder to see if your mounted disk is there.
To run it automatically we need to run the AppleScript every time you login. First we have to save the script as Application. From AppleScript Editor click Save As, Select
File Format as
Application. Click Save button.
Then add it to the Login Items List. Open
System Preferences, click Users & Groups. Select the user or group that you usually use. Select the
Login Items tab. Then click the
+ button to add the AppleScript. Find the script you just created. See the column Kind, make sure you select the one with Application kind.
One more test to check if the script works as what we want. Logout, then login again, wait a few seconds, we have to let Mac run the script and mounting the disk. If you see the Dock carefully you will see AppleScript icon popping up a second when the script is running. Then check from Finder if the TimeMachine disk is mounted.
That is it. Now your Time Machine Disk is automatically connected.