Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that mounts a Samba share to a folder on the desktop, it runs no problem but when its setup as a LoginHook it doesn't mount the folder.

Does anyone have a working login hook that mounts a share that they can post? Or know any issues with mounting shares during login?

This is my Script:

#!/usr/bin/env ruby
@userfolder="/Users/" + @user.to_s
system("mkdir #{@userfolder}/Desktop/everyone")
system("mount_smbfs #{@smbshare} #{@userfolder}/Desktop/everyone | #{@userfolde$
/usr/bin/osascript <<-EOF
        tell application \"System Events\"
                display dialog \"Welcome to the #{@domain} domain #{@user}\n\nY$
        end tell
share|improve this question
What script do you have now? – Chealion Dec 14 '09 at 18:00
How did you set up the LoginHook ? – Studer Feb 18 '10 at 16:47
You might want to follow up up on your questions and respond to the answers you get. – Daniel Beck Jan 5 '11 at 9:45
@Daniel I am not comfortable closing this question. It is has a good answer, and although the OP has given up, this question has had a 1000+ views since it has been asking, so it's definitely drawing people from Google. Weighing that up, I'd rather keep it open. There is a few 100 odd abandoned questions that still provide value to Super User. – BinaryMisfit Feb 17 '11 at 20:37
@Daniel He has made a call on it, and I am not going to override him. – BinaryMisfit Feb 17 '11 at 21:04


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

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

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/'


/sbin/mount -o nodev,nosuid -t smbfs '//Kyle:NotmyPassword@' '/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/

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

In Terminal:

chmod 777 ~/Library/Scripts/NetworkMounts/

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

Try executing the script via Terminal:


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/
  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

I spent the better part of my Friday last week trying to figure this out too. As it turns out, the user logon name is now case sensitive. For example, in my AD users have a logon like "JSmith". Mounting a share with the username "jsmith" fails with "Broken pipe". Mounting with "JSmith" works as expected for me.

I'm using 10.5.8.

share|improve this answer

I've used the following script with success in the past but I haven't used or needed it for a while:

mkdir -p ~/Desktop/Folder
mount_smbfs //domain; /Users/username/Desktop/Folder
share|improve this answer
Looks to me that the folder is created every time the script is executed... is this the intention? – Felix Dec 14 '09 at 19:19
I've fixed the post to make the folder if it doesn't exist. Some operating systems (eg. Mac OS X) depending on how the volume is unmounted (eg. not using umount) will remove the folder as well. – Chealion Dec 14 '09 at 23:33

Instead of a Login Hook you could bind the Mac client to your AD Domain. In the user's AD account you can set the home folder to be your SMB share and configure everything so that the folder mounts at login. Alternatively if this is a shared machine and it's not a user home folder, you could set machine preference to mount a share on the computer at startup. You get the added advantage of AD authentication for your users.

share|improve this answer
Already done, they use AD for authentication but the home folder dont get mounted. Id rather not redirect the home folder as that would mean having uncompressed video/audio flying around the network. Rather have them only copy what they want off the mac into thier domain documents – Arcath Dec 16 '09 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .