Connect to AFP Server Automatically

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:password@192.168.1.10/TimeMachine"
end if
end tell

Change the username and 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 connect_afp_server.

Testing

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.

Run Automatically

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.

Advertisements

3 Responses to Connect to AFP Server Automatically

  1. Josh Crook says:

    Hey I have a quick question.

    I added the script and it works perfectly and I would like to thank you for posting this. This is the easiest procedure that I have found for setting up automatic log in. However, I was wondering if you knew how to automate logging in after a network hiccup in which the end result is being removed from the mounted server.

    I am running an iMac, Macbook pro and a Macmini at my house with the Time Capsule acting as the main router with an Airport Express extending the range throughout the house.

    Ideally I would like to be hooked in to the ‘data’ folder at all times.

    Hope to hear from you soon.

    Joshua

    p.s. This is my very first forum/blog entry of my life. I feel better now haha.

  2. Admin says:

    Hi Josh, I am glad to hear that this article is helpful for you and welcome to blog’s world. That is what I like with blogs. I also learned a lot from it.

    I am just too lazy to click many times to bring me to the shared folder. That’s the reason I wrote this article. If your Ubuntu box is always on, in fact you don’t have to use apple script. You just have to tell your Mac to “remember the password in my keychain”.

    To do this, open Finder, you should see your “Shared” machines on the left pane, select the one that you have. Click Connect button. You will be asked for user and password. Make sure you checked the checkbox of “Remember this password…”. You just have to do this steps once. Every time you open Finder at your MBP, all folders will be in the list, and automatically mounted when you click it.

  3. yoyohat says:

    I just wanted to thank you for this post and for the “Share Folder in Ubuntu 11.04 for Mac OSX Lion” post. You have been so helpful!

    Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: