Tuesday, June 26, 2007

Mount/Unmount Windows shares easily

I used to do this with a custom trigger in Quicksilver but it kept disappearing and now it wont work as I have to turn off Assistive devices access in order to get parallels to behave nicely (annoying!) so I decided to play around with another method to see if I can make it easier.

I regularly mount shares from my XP machine when at home and find going to the Finder, cmd+k and then selecting one from my favourites a pain. This started out as an effort to unmount Volumes in QS in the beginning, turns out you can do one at a time easily through a proxy object, however you can't do the comma trick and do several, so I went hunting the answer in various scripting sites, turned out to be pretty easy to unmount all of them using:
tell application "Finder" to eject (every disk whose local volume is false)
in Applescript of course, bind to a custom trigger and then whenever you want everything unmounted easily just hit your key combo, during this though I came across several scripts to mount shares, lots using alias, automator actions and login items, none of which suited me as I like to mount on demand so to speak, I have about 4 that I use regularly but not usually all at once so I wanted to be able to mount one of my choice at any time and default unmount all when required. It comes down to one useful line:

mount volume "smb://server/share"

But in order to get what I wanted I added the process text action from QS so I could pass a share name as an argument and then bind it to a trigger, so if I want my Movies share mounted now I hit cmd+ctrl+K, text entry for QS pops up, I type movies and hit enter, here's the script

using terms from
application "Quicksilver"
on process text share
if share contains "dis" then
tell application "Finder" to eject (every disk whose local volume is false)
else
mount volume "smb://SERVER/" & share
end if
end process text
end using terms from
** Replace SERVER with your server name if you plan to use
** dis is used to unmount them all, replace with whatever makes you feel good

Save in your default Scripts folder or where ever you've told QS to catalogue them and away you go.

This didn't take long but I've spent twice as long trying to figure a way of passing two arguments so that the first one is SERVER and the second one is SHARE (and possibly third forth etc if I want to do more than one at a time) but it's stumped me, for now.

UPDATE: I actually found some code that allowed me to pass separate words as arguments in the end but then it dawned on me that I was over complicating things again, I've now changed it so I simply pass "server/share" as the argument so I can choose server and share. I don't think I'll do a multi share one unless I feel like messing with argument parsing more....

Technorati Tags: , ,