Skip to content

Instantly share code, notes, and snippets.

@devinberry
Last active August 27, 2016 04:49
Show Gist options
  • Save devinberry/947162ea0d06be5f59cc997bcb0ff3c0 to your computer and use it in GitHub Desktop.
Save devinberry/947162ea0d06be5f59cc997bcb0ff3c0 to your computer and use it in GitHub Desktop.
AppleScript - Needed a simple way to simple unmount all the SMB mounted drives
##################################################################
# #
# First basic script to unmount smb shares #
# #
# Feature: #
# Will only umount non busy filesystems #
# #
##################################################################
property myDisks : {"/Volumes/Gigantor", "/Volumes/ExtraMovies", "/Volumes/StorageDisk", "/Volumes/Music_Compressed", "/Volumes/My_Book", "/Volumes/Music", "/Volumes/MoreMovieS", "/Volumes/Blank", "/Volumes/MacOsX_SoftWare", "/Volumes/miniStorage", "/Volumes/Movies", "/Volumes/My_Book_2", "/Volumes/XtraLarge"}
-- check to see that drives are mounted first shouldnt run if count is 0
set numSmbVolumes to (do shell script "mount | grep smb | cut -d ' ' -f3 | wc -l | sed -e 's/^[ \t]*//'")
-- if there are no smb mounted volumes exit
if numSmbVolumes = "0" then
display dialog "No SMB Volumes are mounted!" with title "ERROR" buttons {"OK"} default button 1
return
end if
-- this means that there some smb drives mounted that will now be unmounted
set mounts to {}
set mounts to paragraphs of (do shell script "mount | grep smb | cut -d ' ' -f3")
repeat with mount in mounts
if mount is in myDisks then
try
-- using diskutil as unix umount needs sudo and eject well just didnt work right
-- using the added option of force, will unmount filesystems that are busy, (corrupt files)
do shell script "diskutil umount " & mount
on error
display dialog "Cannot unmount " & mount & " filesystem busy!." with title "ERROR" buttons {"OK"} default button 1
return 0
end try
end if
end repeat
-- Give a final message that the umount of smb shares is done
display dialog "All SMB mounts have been ejected." with title "Success!" buttons {"OK"} default button 1
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment