Where autofs and launchd fail: Mounting SMB shares.

nwagner
Contributor

I've searched around google, JAMFNation, GitHub, StackExchange, even MacScripter and archives of MacHints, but I cannot find a solution to my problem.

I have a client that wants an SMB share to automatically mount, when a user navigates to a specific path. And I am stuck.

I can do this with NFS shares using AutoFS a la:
Autofs on Mac OS X
Albeit my way is a bit more dynamic, but the concept is the same. But if I try to use SMB the share gets mounted as root and the user can't browse the share. Which leads me to try it with a Launch Agent.

I can kind of mount an SMB share via launchd using a LaunchAgent and WatchPaths as a trigger like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.company.autotest01</string>
    <key>LimitLoadToSessionType</key>
    <string>Aqua</string>
    <key>WatchPaths</key>
    <array>
        <string>/net/test01</string>
    </array>
    <key>ProgramArguments</key>
    <array>
        <string>mount -t smbfs -o soft,noowners,nodev //server/test01 /net/test01</string>
    </array>
    <key>OnDemand</key>
    <true/>
</dict>
</plist>

The program arguments can also be a script but for brevities sake I just put the one liner in there. This actually kinda works. But there are two problems, WatchPaths doesn't trigger the mount unless I run touch /net/test01, once I do touch the path the mount will keep coming back even when I unmount the share and navigate away from the path.

Everything else I can find is about mounting a share on login, which is both trivial and not what I need to do.

I need a way to mount an SMB share when a user navigates to a folder, much like autofs can, but with the unique ability to mount the share as the current user like a LaunchAgent can. Maybe some fusion of the two?

Does anyone have any ideas about how I can do what I am describing?

EDIT: Adding some more info about what I've looked into.
... network shares mounted automatically at login without the finder popping up or passwords stored ...
This is a great project, but again it only mounts on login. However, using the login keychain is a nice touch. We are bound to AD so I don't need that right now. Still cool though.

0 REPLIES 0