So I was looking for a solution to map several network shares at my home on a couple of MacBooks upon logging in. The usual “Login Items” method would work, but would cause the Finder window to open every time the system would login. This is extremely inconvenient as the logged in user then has to close the Finder window themselves.
The solution I came up with was to use AppleScript to write a small app to run at login to map the network drives. Here is the script that I wrote:
Simply replace [protocol] with the protocol type your server/device uses (AFP, SMB, etc.), the ServerName with the name of the server or device, and share with the name doc the network share on the server or device. I have not included the password in the script because it can be typed in the first time the script attempts to connect and saved into the Keychain in MacOS.
You can simply copy the “mount volume” command and add additional network drives to the script. However, any additional network drives you attempt to mount MUST use the same username to connect.
Once you have completed your script and tested it to make sure it works. Simply export it as an application to your Applications folder. Then add that application to the previously mentioned “Login Items” found under “Users and Groups” in the “System Preferences” with the “Hide” box checked to keep the logged in user from seeing it run.
Quick note: If Finder cannot find the server you will receive an error messages that I have yet to figure out how to automate hitting “OK” on. If anyone knows a way to make this work, please let me know!