Unmounting multiple AFP/SMB shares

Hi everyone, after searching high and low, I’ve decided I need to post and ask if anyone can solve this small problem.

At the school I work at, all the windows computers have VBScript-based shortcuts that allow the user to enter their username and password, and the computer will then mount 3 network shares: “Sys”, “NT_4.0” and a user share with the name “USERNAME$” where “USERNAME” changes depending on the user.

In AppleScript I’ve managed to replicate this functionality for our users who prefer to use Macs:

property uName : ""
property uPass : ""
tell application "Finder"
	-- Edit this to your settings
	display dialog "I am now going to mount the network drives." buttons {"Mount", "Cancel"} default button 1 with icon 1
	display dialog "Enter Your User Name:" default answer uName
	set theUser to the text returned of the result
	display dialog "Enter Your User Password:" default answer uPass
	set thePass to the text returned of the result
	set theServer to "smb://192.168.2.50/sys/"
	set theServer2 to "smb://192.168.2.50/nt_4.0"
	set theUserStore to {"smb://192.168.2.50/" & theUser & "$"}
	try
		mount volume theServer as user name theUser with password thePass
		mount volume theServer2 as user name theUser with password thePass
		mount volume theUserStore as user name theUser with password thePass
		display dialog "The Network Drives have been mounted." buttons {"OK"} default button 1 with icon 1
		---- launch the app.
	on error
		display dialog "I'm Sorry, One or all of the network drives are unavailable right now."
	end try
end tell

And it works GREAT!

However when it comes to creating a little scriplet that they can use to immediately unmount all three drives, I have a problem. After searching through the forums, I’ve come up with the following script:

tell application "Finder"
	display dialog "I am now going to unmount the network drives." buttons {"Unmount", "Cancel"} default button 1 with icon 1
	try
		eject disk "sys"
		eject disk "nt_4.0"
		display dialog "You have now been logged out." buttons {"OK"} default button 1 with icon 1
		---- launch the app
	on error
		display dialog "I'm sorry, there was a problem disconnecting the network drives."
	end try
end tell

However I can’t figure out a way to get the script to eject the User share, with it’s variable name.

Any takers?

its almost as quick for me to just drag all three ( i have three i use also) to the trash. But this should probably work? Where JAixon is the logged on user, which is probably the same name as his networked folder?

set userHome to (text of word -1 of (path to home folder as text))
display dialog userHome

What about using the info that was given previously. You could just make the script sit idle in the background. You could just have dialog box that waits in the background and they could click log off and then the drives could be ejected and they could log off all at once.

Hi,

if the server could be named (not just an IP address) and the three shares are the only ones to unmount,
you can use this code (works on Leopard and higher)


tell application "System Events"
	set IDList to id of every disk whose server is "myServer"
end tell

set {TID, text item delimiters} to {text item delimiters, ","}
repeat with i in IDList
	ejectDisk(text item 2 of i)
end repeat
set text item delimiters to TID

on ejectDisk(d)
	tell application "Finder" to eject (first disk whose id is d)
end ejectDisk

The script is to be placed on our intranet for Mac users to download to their personal Macs, we have no control over what their user accounts are called and only assign their network stores.

I like the idea of having the script idle in the background with a “log off” button, kind of like persistent browser windows when using some public wifi points, I’ll float the idea with out IT manager.

@StefanK - This would work great… except the server is only defined by an IP address unfortunately! Ah well, such is the way the cookie crumbles.

thanks for the responses guys, I’ll test them out and see if they’ll work.

If anyone else has a suggestion, please do add to the thread!

Jai

What is displayed when you run this script while the specified disk is mounted?


tell application "System Events"
	display dialog (get server of disk "sys")
end tell

I get a dialog box with “msng” in it, which I assume is the server name.
Taking that dialog output and putting it into the script that you previously submitted, has the results of {“”} being displayed in the lower section of script editor with no disks ejected however.

J