Maestro Monday: (Re)Mount Drives

Keyboard Maestro is a new addition to by tool set and I’ve begun to put it to good use.

Keyboard Maestro is fairly new to me but I’ve already put it to good use. One annoyance I had is having to remount server drives. Sure, I could automatically mount them at login but the connection could be lost, such as when the server rebooted. Enter Keyboard Maestro. I have a script that runs when I logon, when I select it from the menu, and every hour if I’m logged on.

A small bit of Apple Script is needed to actually mount (connect to) the drives. The address for the drive is also needed. I use SMB for the connections rather than AFP (Apple Filing Protocol) but the procedure for getting the connection string is the same, it will just look different than the screenshots. The screenshots are from OS X 10.9.2 Mavericks and Keyboard Maestro 6.4.1. It doesn’t really matter, but my “Server” drives are on a Windows Home Server 2011 box and a Synology NAS.

To get the connection mount the drive manually then do a “Get Info” in Finder. Get the “Server” information under general information.

Since the Apple Script does the real work I could use other utilities or schedulers. But Keyboard Maestro seems like a good place to centralize this and it makes it easy to create the logic.

screenshot of the Get Info screen for the drive

The snippet of Apple Script is shown below along with the info from above:

tell application "Finder"
    try
        mount volume "smb://user@osqwhs02/Archive"
    end try
    
end tell

Note that the user name has to be added to the mount volume command as shown by user@ in the above example. My password is saved in the Mac’s keychain otherwise it would need to be included in the Apple Script.

All this gets put together in a Keyboard Maestro macro:

Keyboard Maestro macro to mount drives

The macro checks to see if the drive is mounted and if it is not then it runs the Apple Script.