Automount network volume (but with different user name)

Discussion in 'macOS' started by stevewynn, Feb 6, 2010.

  1. stevewynn macrumors newbie

    Joined:
    Jan 25, 2010
    #1
    Ive set a number of network drives to be auto-mounted on login by adding them to login items.

    This has worked like a charm until now. Previously I used the same login/password on the remote volumes as my osx login name/password.

    However now I would like to auto-mount the volumes but under a different user name than my osx login name.

    I have no problem logging into the server under the new name and password, but it wont remember the credentials for next login. And that is the issue...

    Ive changed the keychain user/password for the relevant volumes, but at login Im prompted to input the correct password. Also my "old" user name is still typed in in advance (which is the same name as my osx user name btw). Even when I input the new user name and password and tick save to keychain it wont stick next time i login.

    Any ideas how to resolve this? Many thanks! :)
     
  2. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #2
    The problem is that it by default it tries to connect with your credentials. It does this unless you specify some other credentials. Unfortunately, this problem would persist if you use the method of dragging them into your login items.

    Try this script instead:

    Code:
    -- Define username
    property username : "myusername"
    
    -- Define shares
    property mapdrive1 : "afp://" & username & "@server.example.com/share"
    property mapdrive2 : "afp://" & username & "@server.example.com/share"
    property mapdrive3 : "afp://" & username & "@server.example.com/share"
    
    
    -- Mount Volumes
    mount volume mapdrive1
    mount volume mapdrive2
    mount volume mapdrive3
    Paste this into AppleScript Editior. Modify it to your needs and save it as an Application.

    Repeat property mapdriveX and mount volume until you have as many as you need. This also works for smb, so change afp if you need to.

    Remove the drives from your login items, and add this script. If you have credentials saved for the username it will automount.

    EDIT: I had a typo in the script. It is correct now.
     
  3. stevewynn thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #3
    Thank you! This works perfectly! The network drives are smb by the way. I didnt add any info to "afp://" other than making it "smb://". That is correct isnt it?

    Also, the script uses the keychain password correct as i wasnt prompted for a password?

    I also now have the added bonus of not having to close every finder window that opens for every volume. :) :)

    One thing if im not asking for too much: As this action is now a applescript. Is there any way to set a custom volume name to the share as a action in the script?

    smb://ServerName/Volume becomes "Volume"
    Is there a rename it to "Volume (ServerName)" within the same applescript?

    Thank you again!!!
     
  4. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #4
    Yes, it is using the stored value for the username specified in the script.

    As far as I know, you cannot do this with the AppleScript funcition, mount volume. You could do it using shell script and mount_smbfs. You would need to put the password in the script if you did this since Terminal does not pull from Keychain, otherwise you would have to input the password into Terminal.

    It can be done in the AppleScript by shell script and diskutil. However, this requires admin privileges. Which means the script would ask for a password. Or, you would have to edit the sudoers file and give permission to the local admin to run the diskutil command without a password.
     
  5. stevewynn thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #5
    No worries. Just wondering. Not a good idea to put passwords into scripts anyway ;)

    Thanks for all your great help!
     

Share This Page