Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

14UG

macrumors member
Original poster
Nov 11, 2010
68
40
Scotland
I'm writing a script to let a student mount and SMB voume with the minimum of fuss. Unfortunately while the volume mounts fine I can't get it to unmount. Script below, any ideas?

Code:
-- Display log in dialog box
-- Prompt the player to enter their username & password
set username to text returned of (display dialog "Username: " default answer "" buttons {"Cancel", "OK"} default button 2 with title "Mount Student Drive")
set userpass to text returned of (display dialog "Password: " default answer "" buttons {"Cancel", "Log-in"} default button 2 with title "Mount Student Drive")

-- Set the syntax for making a samba mount (& opening it) with the entered credentials
set sambastring1 to "smb://" & username & ":" & userpass & "@blahblah/tshomedir/student/" & username
set sambastring2 to "smb://blahblah/tshomedir/student/" & username

-- Mount the volume
try
	mount volume sambastring1
	-- Check to see if mount has been successful
on error
	display dialog "Wrong username and/or password"
end try

-- Open the volume & bring it to the front
tell application "Finder"
	open location sambastring2
	activate
end tell

display dialog "Don't forget to log out!" buttons {"Log out now"} default button 1 with icon stop with title "Log out"

set sambastring3 to "/Volumes/" & username

tell application "Finder"
	if exists (disk sambastring3) then
		eject sambastring3
	else
		display dialog "Student drive not found or is unmounted already"
	end if
end tell

Specifically it is this bit that isn't working:-

Code:
display dialog "Don't forget to log out!" buttons {"Log out now"} default button 1 with icon stop with title "Log out"

set sambastring3 to "/Volumes/" & username

tell application "Finder"
if exists (disk sambastring3) then
eject sambastring3
else
display dialog "Student drive not found or is unmounted already"
end if
end tell

When I pass the name of the drive to the eject command explicitly I get the following error:-

Finder got an error: Can’t make "/Volumes/0999021tt/" into type item.

OK, I'm an idiot I was passing eject a filepath into the Volumes folder but all I needed to do was give it the name of the disk in question. Simples.
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.