Last active
August 27, 2016 04:50
-
-
Save devinberry/3efa3ccc41a58fb1136904dea65c254f to your computer and use it in GitHub Desktop.
AppleScript - Needed a simple way to mount all my SMB Drives without the Finder opening a window for each one, enjoy ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################## | |
# # | |
# Needed a simple way to mount SMB drives with no Finder window # | |
# # | |
# Native OSX SMB mount construct # | |
# # | |
# try # | |
# mount volume "smb://workgroup;userid:password@ipaddress/drive$" # | |
# end try # | |
# # | |
# Must Change These Values: # | |
# # | |
# smbUser,smbPass,smbServer # | |
########################################################################## | |
-- list of all smb network drive labels | |
property myDisks : {"DriveLabelName1", "DriveLabelName2", "DriveLabelName3"} | |
on run | |
-- set all needed vars with environment specifics | |
set smbUser to "username" | |
set smbPass to "password" | |
set IP_Address to "127.0.0.1" | |
set smbServer to (do shell script "ping -c 1 127.0.0.1 &> /dev/null && echo 127.0.0.1 || echo null") | |
-- SMB server if offline then we should stop and not mount anything as it will all fail | |
if smbServer = "null" then | |
display dialog "SMB server is not pingable have null for IP" with title "ERROR" buttons {"OK"} default button 1 | |
return | |
end if | |
-- this creates a list of "/Volumes/sharename" that are only SMB | |
set mountedDisks to {} | |
set mountedDisks to paragraphs of (do shell script "mount | grep smb | cut -d ' ' -f3 | awk -F '[/]' '{print $3}' ") | |
-- All my smb volumes to mount using this syntax will mount as /Volume/drivename <-- described in servers smb.conf file | |
repeat with aDisk in myDisks | |
if aDisk is not in mountedDisks then | |
try | |
mount volume "smb://" & smbUser & ":" & smbPass & "@" & smbServer & "/" & aDisk | |
on error | |
-- If there is an error this is almost 98% of the time be on the smb server side! | |
display dialog "Mount for share " & aDisk & " failed." with title "ERROR" buttons {"OK"} default button 1 | |
return 0 | |
end try | |
end if | |
end repeat | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment