1 2 Previous Next 17 Replies Latest reply: Jan 14, 2013 3:58 PM by randy_harris
Just J Level 2 Level 2 (160 points)
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
  • 1. Re: Finder Command-K vs. mount_webdav.
    BobHarris Level 6 Level 6 (13,120 points)
    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
  • 2. Re: Finder Command-K vs. mount_webdav.
    Just J Level 2 Level 2 (160 points)
    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.
  • 3. Re: Finder Command-K vs. mount_webdav.
    Linc Davis Level 10 Level 10 (118,305 points)
    osascript -e ' mount volume "http://10.0.1.4:8080" '
  • 4. Re: Finder Command-K vs. mount_webdav.
    Just J Level 2 Level 2 (160 points)
    Linc Davis wrote:
    osascript -e ' mount volume "http://10.0.1.4:8080" '


    Outstanding - that works very well. Thanks!
  • 5. Re: Finder Command-K vs. mount_webdav.
    Linc Davis Level 10 Level 10 (118,305 points)
    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.
  • 6. Re: Finder Command-K vs. mount_webdav.
    BobHarris Level 6 Level 6 (13,120 points)
    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
  • 7. Re: Finder Command-K vs. mount_webdav.
    Just J Level 2 Level 2 (160 points)
    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.
  • 8. Re: Finder Command-K vs. mount_webdav.
    BobHarris Level 6 Level 6 (13,120 points)
    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.
  • 9. Re: Finder Command-K vs. mount_webdav.
    Linc Davis Level 10 Level 10 (118,305 points)
    +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" '
  • 10. Re: Finder Command-K vs. mount_webdav.
    Just J Level 2 Level 2 (160 points)
    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!
  • 11. Re: Finder Command-K vs. mount_webdav.
    BobHarris Level 6 Level 6 (13,120 points)

    #!/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" "
  • 12. Re: Finder Command-K vs. mount_webdav.
    Just J Level 2 Level 2 (160 points)
    Thanks, Bon - that's educational and useful. I'll be incorporating that into my code.
  • 13. Re: Finder Command-K vs. mount_webdav.
    randy_harris Level 1 Level 1 (0 points)

    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?

  • 14. Re: Finder Command-K vs. mount_webdav.
    BobHarris Level 6 Level 6 (13,120 points)

    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.

1 2 Previous Next