Automatically mount SMB shares on login

May 10, '04 09:04:00AM

Contributed by: Ptitboul

To mount a SMB share with the Finder, the classical technique is to go to the Network directory, then to WORKGROUP, then to MACHINE, and then to choose a SHARE. But I want this to be done automatically when I log in. My technique is to run a shell script at login. Using 10.3.0 to 10.3.2, you can simulate the behaviour of the Finder by using this shell command:

cd /Network/WORKGROUP/MACHINE/SHARE
In 10.3.3, the previous cd trick is not working, but the following technique works (mostly):
mkdir '/Volumes/WORKGROUP;MACHINE'
mount_smbfs '//USER@MACHINE/SHARE' '/Volumes/WORKGROUP;MACHINE'
The above is shown as two unique commands; you could write it as a one-line script by separating the commands with a semicolon. One drawback of this mount_smbfs technique is that it does not perfectly simulate the behaviour of the Finder: you cannot eject the share with the Finder, you need to use the Terminal and do it this way:
umount '/Volumes/WORKGROUP;MACHINE'; rmdir '/Volumes/WORKGROUP;MACHINE'
[robg adds: I haven't tested this method. I connect to a number of SMB shares at work, but never logout of my laptop, so I just use a folder of aliases and click one when necessary.]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040430080642734