Results 1 to 13 of 13
  1. #1
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Nov 20, 2007
    Posts
    6
    Question Login Script to Mount SMB Drive to Desktop
    Hello Mac Experts! I just started drinking the Mac Kool-Aid when I ordered my first Mac - a MBP - last week. I must admit it tastes way better than the Windoze 3 day old cold coffee I'm used to. So far I'm loving it, but I'm running into one issue on my work network.

    After trying for 3 hours with our Linux guru we could not get Finder to open a connection to our file/web server which is Debian (Linux) through Samba. I tried everything I could think of and there's not much help on Google.

    Using the command line mount_smbfs I was finally able to mount the samba share on our Debian to a folder in my home directory. Right now this is fine, for the rest of the day I'll be able to work, but I'm just wondering if there is a way I can create a script that runs when I login that does the following:

    1) At login check if my Server is available (192.168.1.216) (this in case I'm using my MBP on the road or from home)

    2) Run this command if the server exists:
    mount_smbfs //myusername:mypassword@192.168.1.216/share /pathto/mountfolder/ondesktop

    3) The last part is the key (I guess) - I want this share to show up on my Desktop like when I connect a USB drive or how my Macintosh HD does

    I'm assuming it's fairlly easy to create a script that runs at login? I've Googled a little with no success but I think the tricky part will making sure the 192.168.1.216 is a valid server -- or maybe there doesn't even need to be a check it just runs the command and if it's not there nothing happens? The other tricky part for me is figuring out where exactly I need to mount the drive to so that it appears on my desktop as a mounted drive instead of in my /Users/username/smbMount folder that I arbitrarily made.

    The later is what I really need to konw as I'm sure with alot of Googling I can find the best way to create a login script in Leopard, but I have no idea where to mount it to and I'm afraid to just start trying to mount to some device in /dev/ which (I think) could potentially screw things up.

    I'm looking for a step by step here if someone wouldn't mind helping out this Mac Newb.

    Thanks in advance!!!

  2. #2
    Login Script to Mount SMB Drive to Desktop
    kirby14's Avatar
    Member Since
    Nov 20, 2007
    Posts
    93
    There is a write up somewhere (maybe on these forums) about using Automator to do this for you. It can definitely map the "drive" but I'm not sure if it will be able to check to see if the server is available first since I've never used it.

    If I find the link, I'll post it here.

  3. #3
    Login Script to Mount SMB Drive to Desktop
    RiDE's Avatar
    Member Since
    Sep 13, 2006
    Location
    Deep in the heart of Texas!
    Posts
    3,566
    Specs:
    Mac's
    While the server is mounted...

    Open System Preferences >> Accounts >>> login items.

    Drag the Server icon and drop it in the Login Items.

    This will mount the server at login.

  4. #4
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Nov 20, 2007
    Posts
    6
    Quote Originally Posted by RIDE View Post
    While the server is mounted...

    Open System Preferences >> Accounts >>> login items.

    Drag the Server icon and drop it in the Login Items.

    This will mount the server at login.
    The problem is I can't access this share using the finder, for some reason Go > Connect To Server... will not allow me to connect to this Debian server using samba. The only way we've found is to Terminal in mount_smbfs - I'm asking if there is a way to do this during start up - I think I found out how by creating a .command file that runs in startup, but I still don't know how to do (1) check if server exists before creating a folder on my desktop and then mounting the file system to that folder.

  5. #5
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Nov 20, 2007
    Posts
    6
    I guess I should have been more clear in my post. For some reason, I cannot use Go > Connect to Server... in the Finder options. I get some type of error to the effect of "You do not have permission to access this drive" - when I type in an incorrect login I get a different error saying "Bad username or password". I can connect to this samba server using Windows and other Linux machines. I can also connect using smb in the command line of my Mac and I can mount the drive using mount_smbfs but for some reason I can't do the easy Finder way.

    This is why I am asking about a start up script since it seems the only way I can access this share is by typing in the command line. I have a basic script going below, however I would like it to remove the two directories it creates first at startup, determine whether I can mount the share, then if I can, recreate those folders (that way if I'm not at work, I won't see the empty folders on my desktop)... Below is my script (.command file set to run at login):

    mkdir /Users/adam/Desktop/blxshare
    mkdir /Users/adam/Desktop/blxweb
    mount_smbfs //username:password@192.168.1.216/blxshare /Users/adam/Desktop/blxshare
    mount_smbfs //username:password@192.168.1.216/blxweb /Users/adam/Desktop/blxweb
    KillAll Terminal
    exit

    So, like I said, first, I need to add a rm /Users/adam/Desktop/blxshare, then I need some way to check and see if 192.168.1.216 exists, if so, recreate the folder and mount the SMB share.

  6. #6
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Oct 27, 2005
    Posts
    4,702
    redbergy, have you successfully mounted the share onto your Desktop so you have the share icon visible? Sorry if you've explained the contrary above.

  7. #7
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Nov 20, 2007
    Posts
    6
    Spawn - No problem, I'm not sure of the definition of "successfully". I am able to create a new folder on my desktop and then mount the SMB share to it successfully if that makes sense -- all using the command line.

    mkdir /Users/adam/Desktop/blxshare
    mount_smbfs //username:password@192.168.1.216/blxshare /Users/adam/Desktop/blxshare

    I cannot get it to "mount" to the desktop using Finder.

    So to reiterate - the OS doesn't make the share icon on the desktop for me, I have to manually create a new folder on the desktop and use a command to mount to that specific folder.

  8. #8
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Oct 27, 2005
    Posts
    4,702
    This may be a bit left of centre to what you are trying to achieve but if you look at the image below:



    When my share is mounted I dragged the icon to the menubar in a Finder window and when the share isn't mounted or if my PC is turned off, the icon reverts to a question mark.

    When I know my PC is on and I want to mount the share I just click on the question mark and the share is automatically mounted:



    I just thought that I should *share* this with you in case it is a workaround.

  9. #9
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Nov 20, 2007
    Posts
    6
    Okay here is my Startup script, currently it supports 2 shares (you can easily edit it to change it to more than 2 or only one) I hope this helps someone else.

    Put this into a file with a .command extension and don't forget to hop in the terminal and type chmod +x myfile.command to make sure it has execute permissions. Drag the command file to your login startup applications and you should be good.
    Code:
    #!/bin/sh
    
    # Put Samba Host IP as Host
    host="192.168.1.xxx"
    
    # Desktop Path with trailing slash
    desktop="/Users/user/Desktop/"
    
    # Share Username
    username="yourusername"
    
    # Share Password
    password="yourpassword"
    
    # Share 1 Name
    shr1="share1"
    
    # Share 2 Name
    shr2="share2"
    
    # Ping the host to see if it exists
    outp=`ping -c 1 $host | grep "0% packet loss"`
    
    # Based on ping create folders and mount 
    # or don't mount and delete folders if they exist
    
    if [ "$outp" = "1 packets transmitted, 1 packets received, 0% packet loss" ]; then
    	echo "Found $host, mounting file systems..."
    
    	# Share 1
    	dir1=${desktop}${shr1}
    	if [ ! -d "$dir1" ]; then
    		# Can't Find Directory So Create It
    		echo "Creating Mount Point: $dir1";
    		mkdir "$dir1"
    	else
    		echo "Found Mount Point: $dir1"
    	fi
    	if [ -d "$dir1" ]; then
    		echo "Mounting..."
    		mount_smbfs //"$username":"$password"@"$host"/"$dir1" "$desktop""$shr1"
    	fi
    
    	# Share 2 
    	dir2=${desktop}${shr2}
    	if [ ! -d "$dir2" ]; then
    		# Can't Find Directory So Create It
    		echo "Creating Mount Point: $dir2";
    		mkdir "$dir2"
    	else
    		echo "Found Mount Point: $dir2"
    	fi
    	if [ -d "$dir1" ]; then
    		echo "Mounting..."
    		mount_smbfs //"$username":"$password"@"$host"/"$dir2" "$desktop""$shr2"
    	fi
    	
    else
    	echo "Could not find $host..."
    
    	dir1=${desktop}${shr1}
    	if [ ! -d "$dir1" ]; then
    		# Can't Find Directory So Do Nothing
    		echo "No Unused Mount Point for $dir1"
    	else
    		echo "Found Unused Mount Point: $dir1"
    		echo "Removing..."
    		rmdir "$dir1"
    	fi
    
    	dir2=${desktop}${shr2}
    	if [ ! -d "$dir2" ]; then
    		# Can't Find Directory So Do Nothing
    		echo "No Unused Mount Point for $dir2"
    	else
    		echo "Found Unused Mount Point: $dir2"
    		echo "Removing..."
    		rmdir "$dir2"
    	fi
    fi
    
    # NOTE: If you have other Shell Scripts, or the Teriminal.app is running
    #       enabling the next line will cause the entire Terminal.app to close.
    #	If you are sure that you can kill the Terminal process feel free to 
    #	uncomment the following line so that the Terminal window the script brings
    #	up will automatically close when finished 
    
    # KillAll Terminal

  10. #10
    Login Script to Mount SMB Drive to Desktop
    giulio's Avatar
    Member Since
    Mar 19, 2007
    Location
    NY USA
    Posts
    1,813
    Specs:
    iMac 5.1 | iMac 7.1 | iPod Touch | iPod Nano
    Here is my solution, which uses automator:

    1. Launch Automator, which will create a new workflow.
    2. From the Finder Library, drag the Get Specified Servers Action into the workflow. Click the [+] and enter the address of your server. Something like cifs://server/share, then click Connect.
    3. From the Finder Library, drag the Connect to Servers Action into the workflow. Be sure 'Use Results from Previous Action' is enabled in the URLs pulldown. (The following three steps are optional. They will open a Finder window focused on the mounted share and set the View for it.)
    4. Add the Finder Action Get Specified Finder Items to the workflow. Click the [+] and select the share you want to automate mounting of. Click Open.
    5. Drag Finder's Open Finder Items Action into the workflow. 'Open with' should be 'Default Application.'
    6. To make sure the Finder honors your preferred view, drag Finder's Set Folder Views action into the workflow. Use the options to your liking.
    7. Select Save As, and set the File Format to Application. I suggest saving it to your user's Applications (~/your_user/Applications) folder, and naming it with the share's name.
    8. In the Finder, navigate to where you saved this Automator app. Drag the new app into your login items window.


    It's never failed. And you don't have to worry about error checking anything like that. It's an app, so it runs in it's own environment, not dependant on terminal/etc.

  11. #11
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Oct 26, 2008
    Posts
    1
    skript
    hello, i was trying to use redbergy's skript, and it writes something like this:

    <code>
    Last login: Sun Oct 26 10:18:48 on ttys000
    jarda-vitkus-macbook:~ jardavitku$ /Users/jardavitku/Desktop/mount.command ; exit;
    Found 192.168.0.148, mounting file systems...
    Found Mount Point: /Users/jardavitku/Desktop/iTunes
    Mounting...
    mount_smbfs: mount error: /Users/jardavitku/Desktop/iTunes: Unknown error: -1
    Found Mount Point: /Users/jardavitku/Desktop/Data
    Mounting...
    mount_smbfs: mount error: /Users/jardavitku/Desktop/Data: Unknown error: -1
    logout

    [Process completed]
    <code>

    creates it two folders with correct names on the desktop, but they are empty.
    Does anyone now where could be a problem? (finder connection works OK, but startup connection doesn't, it writes that host could not be found)

    Question number 2): and if it will connect by a this skript, will it be the same asi finder connection? will i be able to eject it in findet?

    3): how to asociate to that folder same picture as it is in finder-connected smbs ?

    thanks for responds..

  12. #12
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Nov 20, 2007
    Posts
    6
    JaRdaII - Your problem seems to be in the mount_smbfs command:

    mount_smbfs: mount error: /Users/jardavitku/Desktop/iTunes: Unknown error: -1
    It's possible that you'd have to play around with the mount_smbfs command in your Terminal to figure out how you can successfully mount your specific network shares. mount_smbfs has a lot of options - it could be possible that you need to specify something else to get your share working correctly. Once you get it working in the Terminal try changing the script to match your successful command.

    If you don't plan on reusing the script, and don't care that it's modular you can simply change the lines under #Share1 and #Share2 that look like this:

    Code:
    mount_smbfs //"$username":"$password"@"$host"/"$dir1" "$desktop""$shr1"
    mount_smbfs //"$username":"$password"@"$host"/"$dir2" "$desktop""$shr2"
    to something like this:

    Code:
    mount_smbfs //user:password@ip/share /Users/username/Desktop/share
    Obviously you'll hard code your username, password, ip, share's name (share), and the path to the folder on your local machine (the final argument).

    We've since added a new file server and the OS now allows us to mount the drives using Finder - so I haven't looked at this script in a while.

    Edit:

    After looking over your output again it's possible that you could have your share name wrong (since that isn't ever in the output I'm just guessing) - but make sure that the host computer is configured for windows (samba) file sharing and does in fact have a shared folder with a name that matches your script. Again, this should be pretty easy to test out by opening Terminal and using the mount_smbfs command or checking on the host computer.

    Hope that helps!

  13. #13
    Login Script to Mount SMB Drive to Desktop

    Member Since
    Jun 30, 2010
    Posts
    3
    Quote Originally Posted by RiDE View Post
    While the server is mounted...

    Open System Preferences >> Accounts >>> login items.

    Drag the Server icon and drop it in the Login Items.

    This will mount the server at login.
    Heh. Drag/drop! I would *never* have tried this, but I should have known.. Dragging "NormalFolder" from my "PLACES" menu didn't work. Dragging the share itself from the NAS in my "Shared" menu didn't work. But dragging NormalFolder from the share under "SHARED" worked fine, and is exactly the behaviour I was after. (Using 10.6).

    SHARED > NAS (Windows BSOD icon) > Share (with 3 little people icon) > NormalFolder

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Script to mount volume (external drive or disk image) which won't mount..?
    By MaccIngs in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 09-09-2011, 09:05 PM
  2. Mount drive at login silently
    By Bigtwenty in forum OS X - Operating System
    Replies: 3
    Last Post: 11-18-2008, 07:15 PM
  3. Mount NFS/SMB Shares in Terminal so they appear on Desktop
    By icpeanuts in forum OS X - Operating System
    Replies: 3
    Last Post: 05-19-2007, 01:49 AM
  4. mount smb shares on login
    By jakeroberts in forum Internet, Networking, and Wireless
    Replies: 2
    Last Post: 04-25-2007, 06:15 AM
  5. mount network drive automatically on login?
    By gort in forum OS X - Operating System
    Replies: 1
    Last Post: 08-23-2006, 11:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •