Skip navigation

Finder Command-K vs. mount_webdav.

6126 Views 17 Replies Latest reply: Jan 14, 2013 3:58 PM by randy_harris RSS
1 2 Previous Next
Just J Calculating status...
Currently Being Moderated
Apr 3, 2011 9:59 AM
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
  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    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
    MacBook/10.6.6, iMac/i7/10.6.6 w/Magic Trackpad, Mac mini/10.5.6, iPod Touch(4thGen)/32GB/4.2.1, iBook/G4, MacBook Pro/Core2Duo, iMac/Core2Duo
  • Linc Davis Level 10 Level 10 (107,660 points)
    Currently Being Moderated
    Apr 3, 2011 1:09 PM (in response to Just J)
    osascript -e ' mount volume "http://10.0.1.4:8080" '
    Mac OS X (10.6.7)
  • Linc Davis Level 10 Level 10 (107,660 points)
    Currently Being Moderated
    Apr 3, 2011 1:24 PM (in response to Just J)
    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.
    Mac OS X (10.6.7)
  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    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
    MacBook/10.6.6, iMac/i7/10.6.6 w/Magic Trackpad, Mac mini/10.5.6, iPod Touch(4thGen)/32GB/4.2.1, iBook/G4, MacBook Pro/Core2Duo, iMac/Core2Duo
  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    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.
    MacBook/10.6.6, iMac/i7/10.6.6 w/Magic Trackpad, Mac mini/10.5.6, iPod Touch(4thGen)/32GB/4.2.1, iBook/G4, MacBook Pro/Core2Duo, iMac/Core2Duo
  • Linc Davis Level 10 Level 10 (107,660 points)
    Currently Being Moderated
    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" '
    Mac OS X (10.6.7)
  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    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" "
    MacBook/10.6.6, iMac/i7/10.6.6 w/Magic Trackpad, Mac mini/10.5.6, iPod Touch(4thGen)/32GB/4.2.1, iBook/G4, MacBook Pro/Core2Duo, iMac/Core2Duo
  • randy_harris Level 1 Level 1 (0 points)
    Currently Being Moderated
    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?

  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    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.

    MacBook Pro, Mac OS X (10.7.5), 27" iMac, MacBook, MacMini, etc...
1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.