This is a quick script I put together
It allows you to connect to a Windows SMB share from your mac, but only when you are connected to a particular network.
Why? Well, lets say your work uses mostly Windows PCs. They have a shared network drive in the form of an SMB share. But you are blessed with a mac and would like to connect automatically when your computer logs in.
You could of course add a shortcut under 'Go' > 'Connect to Server' in the Finder, but this won't auto mount at startup.
Also, what about when you are at home - you don't want your desktop hanging while it tries to connect to a SMB share that isn't there because you are on the wrong wifi network.
With that in mind, this is fully customisable with Script Editor.app in Applications > Utilities
(Note the purple parts which you need to change to suit)
Download the script here
The first line of the script has a delay of 4 seconds. This is just allow your desktop to finish loading and your mac to finish connecting to whatever wifi network you use. You might want to change this to 20 seconds if you aren't using an SSD drive in your mac.
Next, the second line is just finding the name of the wifi network you are currently on. You don't need to change this. You really only need to edit the bits in purple.
Replace 'yournetworkname' with the name of your wifi network you connect to at work (the one with the SMB shares on).
On the line mentioning
The whole line could read:
Or, another example:
You could even 'file' > 'save as' with this script when you finish editing in Script Editor as an App, put it somewhere safe like your home folder, then have it launch automatically at login by adding it to login items under 'Users & Groups' within 'System Preferences'
Things to note that could catch you out: There's been several different versions of SMB. Not all SMB shares are the same. As of writing this, I think we are up to SMB version 3 on Windows 10. This also matters depending on what version of Mac OS you are using:Back to Forum Listing