Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I currently connect to a Windows (smb) share via the Finder -> Go -> Connect To Server. I have to type in the IP (although I have saved the credentials in my keychain). If I reboot or logout, I have to do this again.

I would like the SMB share I am connecting to always be available as soon as I login. How can I accomplish this?

share|improve this question
    
This was asked previously, in short it can't be done. –  Josh K Mar 29 '10 at 2:26
    
I can see the share's info in the terminal via mount, how about adding this to some sort of script that gets run on logon? –  mindless.panda Mar 29 '10 at 2:35
    
Let me revise my comment, it can't be done with anything built in or added. Sure you can AppleScript just about anything, but that's a stackoverflow question, not a superuser one. –  Josh K Mar 29 '10 at 3:29
    
@Josh K - surprised me as well, but the accepted answer does find a way to do this using built in OS functionality. –  mindless.panda Mar 30 '10 at 12:19
    
I guess I hadn't thought about that. :) –  Josh K Mar 30 '10 at 14:43

7 Answers 7

up vote 7 down vote accepted

Make the share point a login item, and it'll be automatically "opened" (i.e. connected) every time you log on. Go to System Preferences -> Users & Groups -> select your account in the sidebar -> Login Items tab, then drag the mounted share point (you can get it from the Finder's computer view, available under its Go menu).

(Historical note: the preference pane was named "Accounts" in OS X 10.6, but changed to "Users & Groups" in 10.7 and later.)

share|improve this answer
    
This works completely as you described - thank you. –  mindless.panda Mar 30 '10 at 12:18
1  
Gordon - the only problem I'm having with this method is if OSX sleeps and then I unsleep, the share shows up as mounted, but its not browseable. –  mindless.panda May 28 '10 at 16:13
1  
Note from 2014: the path is now System Preferences -> Users & Groups. –  Grandpa Jun 12 at 21:54
    
@Grandpa: Updated; thanks for the reminder. –  Gordon Davisson Jun 12 at 23:43

Overview:

Create a launchd agent (a bash script in this case) to mount us whatever shares we like every couple of minutes. It is not perfect but it works. This is for Samba shares, but you can modify it to do other types.

Made with help from Dave Nicoll's about sharing windows/x iTunes libraries.

I'm using my laptop's wireless card to determine if I am connected to my home SSID. You can of course use anything you'd like for conditional execution.

If you're going to use SSID as a condition for mounting as I have you may find it benificial to alias the Airport utility that ships with OS X to your /usr/bin/. If not skip ahead to the next section.

Open Terminal and run:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
Remember the output of this:

airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'

The Script:

My conditionals check for

  1. The share is not already mounted (line 1-4)
  2. The SSID of our Airport card network is not null (line 5-8)
  3. That our SSID must be equal to a pre-defined SSID, in my case "2600leagues" (line 9)

Open your favorite text editor and start a new file, I called mine MountShares.sh

if [ -d '/Users/kyle/Music/iTunes/Podcasts/' ]; then
        #echo Nothing to do, share is mounted
        exit
else 
    if [ -z `airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` ]; then
       #echo SSID is Null, we're not connected with the Airport to any Network.
        exit
    else 
        if [ `airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` == "2600leagues" ]; then
            #echo SSID is 2600leagues!
            /sbin/mount -o nodev,nosuid -t smbfs '//Kyle:NotmyPassword@192.168.1.5/media/Music' '/Users/kyle/Music/'
        fi
    fi
fi

Next we need to edit line 11 to represent your specific needs. You only need to edit the bold parts:

/sbin/mount -o nodev,nosuid -t smbfs '//User:Password@ServerIP_or_Name/Share' '/Where/You/Want/it_to_mount/'

Example:

/sbin/mount -o nodev,nosuid -t smbfs '//Kyle:NotmyPassword@192.168.1.5/media/Music' '/Users/kyle/Music/'

Now that we have our edited mount command, try running it in Terminal. If it is successful, your share should be available at the mount location. (in my example /Users/kyle/Music/)

Edit the line 1 of the bash script to reflect a file or directory inside the mounted share. If you are going to use the SSID as a condition as I have, you'll want to change line 5 by replacing 2600leagues with your SSID.

Save the bash script in a convenient location. (I use ~/Library/Scripts/NetworkMounts/MountShares.sh)

You now need to make the bash script executable, we use chmod to do this.

In Terminal:

chmod 777 ~/Library/Scripts/NetworkMounts/MountShares.sh

If the network share is still mounted, make sure you unmount/eject it now. (Finder works)

Try executing the script via Terminal:

~/Library/Scripts/NetworkMounts/MountShares.sh

If all goes well your share should be mounted. Now all that is left to do is make it so the script runs every so often. Normally you would use crontab for this sort of thing, but 10.6 has deprecated it. Apple would rather you use their launchd service.

Making the launchd Agent

To help you make a launchd agent get Lingon from sourceforge.

  1. Open Lingon
  2. Create a new User Agent (My Agent)
  3. Give it a name such as com.kyle.MountShares
  4. Choose or type the path to the bash script ~/Library/Scripts/NetworkMounts/MountShares.sh
  5. Specify when you would like it to run. (I have Run when it is loaded by the system and *Run it every 10 minutes)
  6. Save it
  7. Exit Lingon

That's it

Let me know if this helps; I typed all this out as fast as possible.

share|improve this answer
    
Wow - awesome! I have been using Gordon's answer so far, but this one seems a little more foolproof. One question - will this persist if the computer goes to sleep? I'm having problems where if I have the share as a login items and OSX sleeps, I lose the share. It shows up still as mounted, but can't browse it. –  mindless.panda May 28 '10 at 16:12
    
I haven't had that problem on 10.6.3. Honestly though, if you're on 10.6 the best utility to be using for this kind of thing is 'auto_master' I've not been able to get master_auto to work satisfactorily, so I still get by with this. macosxhints.com/article.php?story=20100203124656707 –  milkman May 29 '10 at 5:30
    
I guess I'm just being lazy with not plunging into reading the docs on auto_master. –  mindless.panda Jun 2 '10 at 18:05
    
I tried again with auto_master still getting errors with it. This script seems to be my ticket for now –  milkman Jun 3 '10 at 16:13

With auto_fs, auto_master, etc, try having a read of Autofs: Automatically Mounting Network File Shares in Mac OS X (PDF). It's a little dated now (2009) but, using the examples in the doc, I got all my NFS & SMB shares organised and auto mounting easily.

share|improve this answer

Have you looked at auto_master(5)? At a glance it looks possible, but it looks like it could be a lot of work to get set up.

share|improve this answer
    
This is relevant: stress-free.co.nz/automounting_samba_shares_in_leopard –  mindless.panda Mar 30 '10 at 1:58

System Preferences > Sharing > File Sharing > Option > Share Files and Folders Using SMB . I think it can recognize sharing settings. If not, you can add smb share to your favorite server too.

If you want to add it as a favorite server, hit Apple+K while in Finder to bring up the Connect to Server dialog box. Type in the address and then click the + next to the address. It will then be added to the below area Favorite Servers.

share|improve this answer
    
The place you mention in System Preferences has nothing to do with auto mounting a share. How do I add to favorite server as you mentioned? –  mindless.panda Mar 29 '10 at 2:34
    
I'm sorry, but nothing in this answer applies to my question. You pointed me to enabling SMB and how to use Finder favorties. –  mindless.panda Mar 30 '10 at 1:49

My solution is to use Automator and create a small app that automatically connects, then set it to start at login.

Start Automator and select Application, and under the Files and Folders Library you should see Get Specified Server and Connect to Servers. Add those in that order, and add your ip address and share name (if applicable).

At this point you could save it as an application (~/Applications is a good place). Then add it to your login items through Systems Preferences > Users.

However, I added in Automator a 30 second Pause (from Utilities library), and four Loops of 1000 iterations. That should keep it running until I logout or reboot.

Note: it will pop-up a somewhat useful dialog if it cannot connect:

Connection failed

The server "x.x.x.x" may not exist or it is unavailable at this time. Check the server name or IP address, check your network connection, and then try again.

Note: it does not check to see if it is already connected. There may be a way to check the output of Connect to Server

share|improve this answer

There are a couple of solutions here, the simplest of which (IMHO) I will repost below:

From a terminal:

sudo vifs

If not familiar with vi: Hit 'i' for insert (edit mode), then paste this on a new line:

smbserver:/share /Volumes/mount_point url automounted,soft,url==cifs://user:pass@smbserver/share

Hit Esc and then zz to save and exit.

Finally:

sudo automount -vc

Now, when hitting /Volumes/mount_point in the console/finder/whatnot, the share will be automatically mapped.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.