r/applescript • u/sirleechalot • Dec 02 '23
Creating a script to monitor the status of an SMB mount
I'm running Plex on my m1 mac mini and the files that plex serves are stored on a server I run and are shared via SMB. Whenever I restart the server that hosts the files, the SMB share gets unmounted on my mac and plex loses access to the files. I'm trying to write a script to check if the folder is mounted, and if not, mount it. After a little messing around, i've come up with the following:
tell application "Finder"
if not (disk "media" exists) then
do shell script "open " & "smb://camaro/media"
display notification "Samba share was not mounted, remounted it." with title "Mount Status"
end if
end tellThat works fairly well. My only gripe with it is that it pops open a finder window in the case where it isn't mounted, but it only does that once. I had tried using a mount_smbfs command but i started running into permissions issues and this mini is really only used for plex and some other server style duties, it's not being used as a desktop.
My question revolves around how to automate this. Ideally, i would like to have it run once every minute or so. My first instinct (coming from a linux background) would be to use cron for this, but i've also seen posts about having the script run as a service and have the script manage the time check interval. Was just looking for opinions on the best way to handle that aspect of this (and i welcome any feedback on the script itself as well).





