SOLVED: Struggling to get Applescript to unmount an SMB volume

Discussion in 'Mac Programming' started by 14UG, Nov 11, 2010.

  1. 14UG, Nov 11, 2010
    Last edited by a moderator: Nov 11, 2010

    macrumors newbie

    Joined:
    Nov 11, 2010
    Location:
    Scotland
    #1
    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.
     

Share This Page