uɐʎɹ ррoʇ uɐʎɹ bio photo

uɐʎɹ ррoʇ uɐʎɹ

Hello. Is is me you're looking for?
僕は猿ーロボット。
robotic life signs.
makes noise, hears sounds, intafon.
affe auf deux roues.

Email Twitter Github Github Gist Last.fm Soundcloud Flickr

*Update (2007-01-05) – forgot to change this a long while ago, but was looking at some posts online and remembered that I hadn’t updated this. The .nsmbrc file, as it turns out, isn’t really necessary, as the finder will likely prompt you to enter the password for a share that you are trying to mount using the code in the applescript included here. If you like, at that point, you can enter your password and save it to the keychain, which is more secure than saving the password in the .nsmbrc file. Original article follows:

More may follow on this later, if I can determine a decent way of implementing this as a distributable applet, but what follows is a decent way of getting around the awkward samba dismount problem that I discuss in my earlier post.

To recap, there are some problems when developing on your Mac where you need to utilize a consistent volume location through an smb connected shared drive. (A good example of this is developing a project through Eclipse and wanting to write an Ant script that as one of its targets installs the build on the samba connected volume (which could be your development server environment).) A) Sometimes, remounting the shared volume results in unexpected naming in your /Volumes directory – so a windows share “D$” now becomes “D$-1″, so now your Ant script will fail. B) Personally, I have grown to dislike the OSX connect to server dialog window – there is a lack of control there and a lack of knowing exactly what is going on. C) Running a mount_smbfs begins to solve the problems above, but is only part of the solution.

So, as I said, the mount_smbfs command in the terminal does allow you to specify a particular directory to use as your mount point for a shared volume. However, without tweaking your system, you can only access the share through the terminal (Ant scripts running through Eclipse can’t access the drive either). The following is the [hacky, convoluted] solution:

Change the permissions on /Volumes For any of the users on your machine to access /Volumes for what we need to do, the permissions must be changed. Changing the permissions also allows the mounted directory to be accessed via the Finder (and Eclipse, etc.), rather than just in the terminal. Launch the terminal. (NOTE: you must have the root user enabled.) Type the following, hit enter, and enter the root user password when prompted:

sudo chmod 777 /Volumes

Define Your Variables Figure out what the different pieces of information are that you need (will be used in the following sections). {shareAddress} = the ip address or computer name to which you are linking {shareLoginName} = the user name used to login to the remote computer {computerShare} = the sharepoint on the computer (such as C$ if C: were shared on the windows machine) {sharePassword} = password for the share {shareWorkgroup} = the workgroup for the share login {localMountDir} = the directory which is aliased as the remote mounted drive – name this what you want (I used “wsd” for windows shared drive).

Edit your .nsmbrc File Go back to the terminal and navigate to your user folder (type “cd ~/” and return). Edit the .nsmbrc file using pico (type “pico .nsmbrc” and hit return). Type the following in the pico editor (substituting the terms in the curly braces with the info you collected above):

[{shareAddress}:{shareLoginName}:{computerShare}]
addr={shareAddress}
password={sharePassword}
workgroup={shareWorkgroup}

If the file already has contents, just enter the lines below what exists (leave a blank line in between). When you are done, hit Control-X, then hit Y to agree to save the changes, and you are done with that (back to your prompt in the terminal). Now chmod that file to 0600 (type “chmod 0600 .nsmbrc” and return). The .nsmbrc file is referenced when you call the mount command, so that the login information and password is ready-at-hand. Chmod’ing it to 0600 provides system permissions protection for your password therein.

Create a little Applescript app (why not?) Open the Application/Applescript/Script Editor application and create a new script (probably will open a new one by default). Enter the following code in the window, again replacing the curly bracket terms with your information.

set shareUser to {shareLoginName}
set shareLoc to {shareAddress}
set mountDir to {localMountDir}
--
set volumesDir to ":Volumes:" & mountDir
set cmdDir to "/Volumes/" & mountDir
--
try
alias (volumesDir)
-- // do nothing if it exists
on error
-- // create the file if it does not exist
do shell script ("mkdir " & cmdDir)
end try

do shell script ("mount_smbfs //" & shareUser & "@" & shareLoc & " " & cmdDir)

display dialog cmdDir & " is mounted."

Basically, this applescript determines whether or not the directory to which you would like to mount the smb volume already exists (which the OSX connect to server fuctionality doesn’t do), and if not, creates it. Also, unlike the connect to server window, you can specify what you want it to be called. The shell command is then called to mount the shared volume. As a final touch, when the volume is mounted (which can take a little bit of time), an alert pops up to let you know that the smb mounted drive is ready to go.

Now, in Script Editor, choose File/Save As. Enter a name to save as, choose the File Format of “application bundle” from the drop down menu, click off the “Startup Screen” checkbox and save. (incidentally, application bundles are now universal binaries, and I believe the application format is still run through Rosetta on the newer Macs)

Now you should be able to simply double-click your little applescript app whenever you want to connect to the remote server of interest without opening the terminal or the connect to server window. You can access the shared drive by navigating to Volumes on your hard drive. At some point here, the drive will show up as a server in your finder window and will be named whatever its name is designated on the remote machine – regretably, clicking the eject button won’t dismount it (this method isn’t perfect after all). You can unmount the drive by typing “umount /Volumes/{localMountDir}” in the terminal and hitting return…