2007/12/01

MOSX: Open a subfolder on a share, whether the share is already mounted or not

Mac OS X's "open" shell command is powerful - though strangely dependent on the mount state of shares.

Executing
open afp://server.example.com/share/top-folder/sub1/sub2

Will open the share - and, if the share was already mounted, ignore the rest of the path.

So, here's a quick command (make sure it's all one one line) that will open the subfolder, whether the share is already mounted or not:
if [ -d /Volumes/share ]; then open /Volumes/share/top-folder/sub1/sub2 ; else open afp://server.example.com/share/top-folder/sub1/sub2 ; fi

Adaptation for other protocols (ex: SMB), other mountpoints and error-checking are left as an exercise for the reader. :)

No comments: