Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 11, 2010, 07:20 AM   #1
14UG
macrumors newbie
 
Join Date: Nov 2010
Location: Scotland
SOLVED: Struggling to get Applescript to unmount an SMB volume

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 dejo; Nov 11, 2010 at 12:15 PM. Reason: Consecutive posts.
14UG is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Incremental volume adjustments with AppleScript? wrignj08 Mac Programming 5 Jul 28, 2013 05:41 AM
Issues Lowering Volume of Spotify with AppleScript macman7002 Mac Programming 0 Mar 18, 2013 08:07 PM
Mount ssh volume with Applescript MacPC Windows, Linux & Others on the Mac 2 Feb 18, 2013 05:36 AM
AppleScript to zip sub folders on a volume kevinless Mac Basics and Help 2 Nov 11, 2012 05:37 PM
Applescript to unmount/mount drive on identifier other than volume name? mixvio OS X 10.8 Mountain Lion 0 Sep 6, 2012 04:20 AM

Forum Jump

All times are GMT -5. The time now is 08:27 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC