Last active
February 12, 2019 18:24
-
-
Save envygeeks/1f0992a2c07c2f23553a18601300672f to your computer and use it in GitHub Desktop.
Mount SMB on Boot
This file contains hidden or 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
set smbHost to "192.168.1.3" | |
set closeOnUnmount to {"iTunes"} | |
set volnames to {"Storage", "Movies"} | |
set tmVolname to "Backups" | |
set idleTime to 120 | |
set maxWait to 60 | |
on idle | |
tell application "Finder" | |
repeat with vol in volnames | |
try | |
if not (exists disk vol) then | |
mount volume "smb://" & smbHost & "/" & vol | |
set i to 0 | |
repeat until name of every disk contains vol | |
delay 1 | |
set i to i + 1 | |
if i is greater than maxWait then | |
error "Unable to mount the given volume '" & vol & "', there is a problem." | |
exit repeat | |
end if | |
end repeat | |
end if | |
if not (exists disk tmVolname) then | |
tell application "System Events" | |
set volPath to the POSIX path of the alias ("Volumes:" & vol as string) | |
set volPath to quoted form of volPath & "/" & tmVolname & ".sparsebundle" | |
if exists file volPath then | |
do shell script "hdiutil attach " & volPath | |
set i to 0 | |
repeat until name of every disk contains vol | |
delay 1 | |
set i to i + 1 | |
if i is greater than maxWait then | |
error "Unable to mount the given volume '" & vol & "', there is a problem." | |
exit repeat | |
end if | |
end repeat | |
end if | |
end tell | |
end if | |
on error errorStr | |
log "Got '" & errorStr & "' while trying to mount '" & vol & "'" | |
end try | |
end repeat | |
end tell | |
return idleTime | |
end idle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment