Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Finder Command-K vs. mount_webdav.

I have a WebDAV server (an iPhone running Olive Toast's "Files" app) that I can mount via Finder by hitting Command-K and then entering the server address (in this case, "http://10.0.1.4:8080") mounting as a guest (so, no username or password entry needed). The server then appears as "10.0.1.4" under the Shared group in the Finder sidebar, and the path shows as "/Volumes/10.0.1.4".

What I can't figure out is the correct Terminal/Shell command to perform the same function and get the same result, preferably without any user input required.

Any suggestions are welcome. Thanks.

MacBook Pro 17" (Early 2011), Mac OS X (10.6.7), iPhone 4 32GB / iPad 64GB 3G

Posted on Apr 3, 2011 9:59 AM

Reply
17 replies

Apr 3, 2011 12:40 PM in response to Just J

I am not in a position where I can test this, however, I think the general approach would be

mkdir -p /path/to/your/mount/point # mount command needs mount point dir to already exist
mount -t webdav http://10.0.1.4:8080 /path/to/your/mount/point

When you are ready to unmount the mount point, you can

umount /path/to/your/mount/point

You could also try an Automator app where you pass the IP address via a command line option, Or Applescript. There are forums for these where knowledgeable people hang out.

You could also try using the 'open' command, however, this will pass the URL to your default web browser, and hopefully it will be smart enough to do the mount for you.

open http://10.0.1.4:8080


Message was edited by: BobHarris

Apr 3, 2011 12:52 PM in response to BobHarris

Thanks, Bob. It's the mount point that I am having trouble with. If I want to mount so that the files appear in /Volumes/10.0.1.4 (which is what happens when I use Cmd-K to mount the server), what is the syntax for the mount point? Assume the user account name is "X", and the machine's hard drive is the standard "Macintosh HD". Do I use "/Volumes"? "/Volumes/"? I've lost track of the different variations I've tried to no avail.

Apr 3, 2011 5:14 PM in response to BobHarris

mkdir -p /path/to/your/mount/point # mount command needs mount point dir to already exist

mount -t webdav http://10.0.1.4:8080 /path/to/your/mount/point
{code}

FYI. I am finally somewhere I can test the mount command, and it does work.

I do understand that this method does NOT provide a /Volumes/10.0.1.4 mount point, but I did want to make sure anyone that wanted to use the mount command would have a working example

Apr 4, 2011 3:16 AM in response to Linc Davis

Linc Davis wrote:
I'm glad to hear it. One caution though: the 'osascript' command returns immediately, and its exit status doesn't reflect whether or not the mount succeeded. So you need to be careful about assuming that the volume is mounted in the rest of your script.


Good to know. I'll put in some combination of a loop, sleep command, and a test for the presence of something on the target volume.

One last question: how can I pass the IP part of the mount volume command as a parameter to the shell script. I would think something like


#!/bin/bash
osascript -e ' mount volume "http://$1:8080" '


but I'm having a hard time sorting out the interaction of the single and double quotes in order to get the substitution to take place.

Apr 4, 2011 6:17 AM in response to Just J

One last question: how can I pass the IP part of the mount volume command as a parameter to the shell script. I would think something like


#!/bin/bash
osascript -e ' mount volume "http://$1:8080" '


but I'm having a hard time sorting out the interaction of the single and double quotes in order to get the substitution to take place.

Single quotes protect everything except a single-quote.

Double quotes allow substitutions.

This should work:

#!/bin/bash
osascript -e " mount volume "http://$1:8080" "

I've chosen to use backslashes to protect the "http://$1:8080" double quotes as I am not sufficiently aware of Applescript quoting rules.

Apr 4, 2011 7:08 AM in response to Just J

+I'll put in some combination of a loop, sleep command, and a test for the presence of something on the target volume.+

The df command can be used to test for the presence of a mounted filesystem.

+One last question: how can I pass the IP part of the mount volume command as a parameter to the shell script.+
osascript -e ' mount volume "http://'$1':8080" '

Apr 4, 2011 7:24 AM in response to Linc Davis

Thanks for the continued help, gentlemen.

Linc Davis wrote:
+I'll put in some combination of a loop, sleep command, and a test for the presence of something on the target volume.+

The df command can be used to test for the presence of a mounted filesystem.

+One last question: how can I pass the IP part of the mount volume command as a parameter to the shell script.+
osascript -e ' mount volume "http://'$1':8080" '


Perfect - that worked like a charm, and now everything is working the way I want it, albeit with Automator calling a shell script that invokes an AppleScript command - whew! 🙂

Apr 4, 2011 11:58 AM in response to Just J


#!/usr/bin/env bash
WEBDAV="http://$1:8080"
MNT="/volumes/$1"
#
# Is there already something at /Volumes/$1
#
if [[ -e "$MNT" ]]
then
if [[ $(/usr/bin/stat -f "%d" "$MNT") != $(/usr/bin/stat -f "%d" "$MNT/..") ]]
then
echo "Something is mounted on $MNT"
exit 1
else
echo "$MNT is a directory that may interfere with mounting $WEBDAV"
exit 1
fi
fi
#
# no volume is already mounted, and there is no dangling directory in /Volume
#
# Mount the webdav
#
osascript -e " mount volume "$WEBDAV" "

Jan 9, 2013 11:38 PM in response to BobHarris

Bob,


I'm trying your method as I believe it would let me mount a Webdav with a name of my choosing. I can't get it to work though.


In Finder if I connect to server, enter the WebDav servers IP address and port number it connects fine, and I see the connected server on my desktop.


When I run through what you show for a terminal Webdav connection it doesn't work.


Any tips?

Jan 10, 2013 4:45 PM in response to randy_harris

I've done some testing. The 'open' will not work. However, the osascript does.


Which one are you interested in?


As as for name, are you talking about the username to login with?


osascript -e ' mount volume "http://username@webdav.address:portnum" '


-OR-


osascript -e ' mount volume "http://username:password@webdav.address:portnum" '


However, I do not advise storing a password in a script.

Jan 10, 2013 7:10 PM in response to BobHarris

Bob, glad you replied. Here's what I'm trying to do.


I can connect to the webdav via the osascript. I also don't like putting usernames and passwords in flat files, seems that keychains works for that anyway.


What I'm trying to do is this. We have a Synology Diskstation at work, many of us connect to it's Shared [network] Folders via Webdav. When we're in the office we like to connect directly on the LAN for improved connectivity. When remote we use an external address.


I've created this little script which tests to see if the Synology is local and if so connects to it directly on the LAN, if it's not found then it connects from the external IP address.


#!/bin/bash



echo



echo "about to ping LOCAL"

/sbin/ping -c 1 -t 5 LOCALIP



/sbin/ping -c 1 -t 5 LOCALIP &>/dev/null



if [ $? -eq 0 ]; then

echo

echo "About to mount to LOCAL Webdav..."

osascript -e ' mount volume "http://LOCALIP:WEBDAVPORT" '

else

echo "About to mount to ETERNAL Webdav..."

osascript -e ' mount volume "http://EXTERNALIP:WEBDAVPORT" '

fi



For all practical purposes this works great. The one drawback is that when connected locally the mounted webdav has the name LOCALIP, and when connected from outside of the office the webdav mounted drive has the name EXTERNALIP (it's actually the IP address like say 192.168.0.55). I'd so love it if I could connect locally or remotely and regardless of where I'm connecting from have the same webdav name. Say maybe WEBDAV as the connected file name.


I've tried to accomplish this by mkdir a folder in the Volumes directoy and try using the mount_webdav command but I flat out couldn't get it to work.


Really appreciate any help.

Finder Command-K vs. mount_webdav.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.