8

I got a late 2017 macbook pro running the High Sierra update. I am wondering if its possible to auto connect to a smb server. I need to do this manually everytime i start up at work. And as small as it is. It gets quite annoying!

I have found a way to connect to AFP servers using a script (but im not using any) but that didnt work for me.

Thanks!

2 Answers 2

15

There's a number of options for doing this, but the easiest way is to just use your Login Items. More specifically:

  1. In the Finder, press CommandK (or click on the Go menu and select Connect to Server...)
  2. Now enter the server address
  3. Click on the Connect button
  4. IMPORTANT: If you're a registered user, when entering your login details you must ensure you enable the option for remembering your password in keychain
  5. Once connected, go to Apple > System Preferences > Users & Groups
  6. Select the Login Items tab
  7. Now navigate to the mounted server (e.g. on your desktop) and drag it to the Login Items list
  8. OPTIONAL: If you don't want the server window to open every time you startup, you can click on the Hide checkbox on the left of the server in the Login Items list

NOTES:

  • At step 4 the reason I say you must opt to remember the password is that macOS needs to remember this in order to be able to log in automatically!
  • At step 7, if you don't see the server mounted on your desktop, then go to Finder > Preferences > General and tick the checkbox for Connected servers.
  • Keep in mind that if for whatever reason your Mac can't connect to the server, this may in fact become more annoying then having to connect manually.

If your server doesn't mount on the desktop

If you can't get the server to mount on your desktop, try following these steps instead:

  1. Go to Apple > System Preferences > Users & Groups
  2. Select the Login Items tab
  3. Click on the + button at the bottom of the Login Items list
  4. In the window that opens, click on the server in your left Sidebar (or navigate to it)
  5. If you're not already connected to it, then connect to it through this window. (IMPORTANT: If you're a registered user, when entering your login details you must ensure you enable the option for remembering your password in keychain)
  6. Once connected, navigate to and select whichever folder on your server you use the most
  7. After a moment the add button will become active. Click on this
  8. Now the folder you selected at Step 6 will be added to your Login Items
  9. OPTIONAL: If you don't want the server window to open every time you startup, you can click on the Hide checkbox on the left of the server in the Login Items list

To show network mounted volumes (SMB, AFP, NFS, etc.) on your desktop, issue the following command in Terminal:

defaults write com.apple. finder ShowMountedServersOnDesktop —bool true
16
  • The server does not create a desktop icon of the server. It only appears in the sidebar in Finder.
    – Granny
    Nov 27, 2017 at 7:51
  • Ah, okay, I've just added an extra note re Step 7.
    – Monomeeth
    Nov 27, 2017 at 8:50
  • I already had it checked, still no server on the desktop.
    – Granny
    Nov 27, 2017 at 9:09
  • Any way i can do it without having it on the desktop?
    – Granny
    Nov 28, 2017 at 10:15
  • Sorry, I somehow missed your comment. When I get a chance I'll come back and revisit this for you, although it may not be until tomorrow sometime.
    – Monomeeth
    Nov 29, 2017 at 6:40
0

I have found a different solution that allows me to automate the process even further.

Here is the code I use:

tell application "Viscosity"
    set connectionState to "dunno"
    repeat until (connectionState = "Connected")
        if connectionState = "Disconnected" then
            connect "VPN_CONNECTION1"
            connect "VPN_CONNECTION2"
        end if
        set connectionState to state of connections where name is equal to "VPN_CONNECTION1"
        set connectionState to connectionState as string
    end repeat
    tell application "Finder"
        activate
        if (count of windows) is 0 then
            mount volume "smb://username:password@IP_address/share"
            mount volume "smb://username:password@IP_address/share"
        end if
    end tell
end tell

The above apple script will automatically startup my Viscosity VPN and upon a succesfull connection it will start to connect to my SMB servers. If you export the code to an application and then put it into your login items it will automatically connect everytime you startup.

Hope this helps anyone.

Kind regards, Granny

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .