Applescript for mounting Windows Shares

I have scoured the web for this script for mounting windows shares in OS X. I am compiling it as an application and dropping it into the startup items:
tell application "Finder"
activate
try
mount volume "cifs://SERVER/SHARE"
end try
end tell
My question is this: I have a MacBook(Pro) and use it at home and at work... I have scripts setup for both locations, to mount various shares, but when I'm at home and the work scripts run, they fail to mount (because I'm not on the work network), or when I'm at home, the work shares fail to mount, generating a dialog with something to the effect of "couldn't find that share"... I've got a dozen of these scripts, it would be nice if it would just silently fail, rather then generating multiple dialogs.
I was thinking of making the apple script check my ip address, and if it returns a work IP address, then it would go onto talking to the finder, if it doesn't find a matching IP address, then it would just end.
Or, somehow have applescript ping the server that it's trying to connect to, and on success, run the script, and on fail just end it.
Any thoughts?
Thanks,
Dan Ormsby

You should probably post in the AppleScript forums:
http://discussions.apple.com/forum.jspa?forumID=724

Similar Messages

  • Finder can't access a mounted windows share - but the Terminal can...

    When I mount a drive using the finder's "Go / Connect to Server..." command I can choose the share to connect to and Finder mounts the share, puts it on the desktop etc... but then it tells me that:
    "The folder “Sharename” can’t be opened because you don't have permission to see its contents."
    Any attempt to access the folder through the finder will result in the same error message.
    Since the share does otherwise mount sucessfully, it shows up in /Volumes/ and using the terminal I can access the contents of the drive and open files. Applications, both terminal and GUI can read and save to files and folders opened in this way, but the GUI application cannot find the path again if you browse away in the app's browsable dialog boxes (like Save or Open). I can access any file using an absolute path in any program.
    There are more nuances to this behaviour:
    Other shares hosted by the same server don't have this problem.
    Using the terminal, I appear to have the same Unix permissions to the files and folders on the shares that work as the ones that don't work.
    Using Finder's "Go to Folder..." command I can open some, but not all folders in the flaky sharepoint mounts. All files seem to work though.
    My guess is that there are some permissions that are making Finder unhappy, but I'm not sure what they might be. But regardless, why then can I access everything from the Terminal? I'd like to use the Finder - it makes my experience much smoother!
    Some other people in this forum seem to have had the same problem with their NAS drives, but I don't think anyone has yet suggested they try accessing it via the terminal. It would be really helpful if anyone could confirm this Finder/Terminal discrepant behaviour.
    Any thoughts?

    I am having the same problem but with OS X 10.9 (Mavericks).
    I try to connect to the NAS via the Go / Connect to Server utilizing smb or cifs protocols and it will mount but then I can't enter the mounted drives/directories with finder.
    The workaround for forcing smb1 has been applied and I find that Finder would not permit me to enter those mounted directories but I can go via the command line and work fine. The  only issue is that with a Mac, as much as everybody say, you should not need to go to the command line... Yeah, right.
    For the amount of money that I paid for the Mac Book Pro, it should work. So, now I can confirm that even Mac OS X can be as bad as Windows...
    Any idea when will Apple put out a fix or an update to finder?

  • How to mount windows share as a drive letter?

    I have a user that has interlinking excel spreadsheets that are located on a network share. Spreadsheet A on K: links to Spreadsheet B on K:. The links in excel are defined as K:\adirectory\spreadsheetb.xls...
    How do I mount a drive on a Mac, such that MacOffice will be able to follow the links?

    *"How do I mount a drive on a Mac, such that MacOffice will be able to follow the links?*
    Sorry, but you don't, at least not in that sense, as Macs don't follow Windows drive letters.
    The user will have to mount the same share on the Mac desktop and link to it via standard SMB links an hope that the links translate server for server and share for share.

  • Trying to write an application to mount Windows Share in osx

    Hello,
    I am very new to the osx environment and I was hoping someone could point me in the right direction. I have a decent amount of programming experience in windows environment, but absolutely no experience writing apps for osx. I would like to write an application that users can launch, enter their credentials and connect to a windows share which I have already designated for them. I can easily do this in automator, however I was hoping to create something where there is a little less confusion. I haven't had any luck finding any resources on this topic and I was hoping someone could give me a little guidance. thanks for your time.

    I managed to make it work.
    I did entry as below in /etc/fstab
    //192.168.1.1/RHEL5 /mnt/win cifs credentials=/etc/
    smbcred 0 0
    run
    mount -a
    /etc/smbcred file contains username and password
    now it is mounted as read write mode.
    ~

  • Samba mounting windows share

    Hi, I'm trying to mount a windows share but all I can do after mounting is seeing the folders and files on the share. I can not read any file, I get "permission denied". On windows everything should be set to allow for the files to be read (if my brother didn't forget, overlooked anything). I even disabled the windows firewall.
    The windows 2000 computer can access the arch linux samba shares without a problem.
    I'm running arch current up to date.
    Here's how I mount, as root:
    mount -t smbfs -o username=gast,password=gast //192.168.0.132/Muziek /mnt/LW/Muziek/
    (gets mounted succesfully, but I can't read the files)
    Here's my /etc/samba/smb.conf:
    #Global Parameters
    [global]
    workgroup = THUIS
    netbios name = gel
    passdb backend = smbpasswd
    force create mode = 0770
    force directory mode = 0770
    wins support = yes
    case sensitive = no
    encrypt passwords = yes
    security = share
    server string = Linux                 
    [share]
    path = /mnt/hda1
    public = yes
    only guest = yes
    writable = no
    printable = no
    create mask = 777
    Can anyone help me out? I've been trying to get it working for at least a few hours :s.

    You are right. I did not need the dir_mode and file_mode, and I did have full control enable, but no dice.
    However it seems there is a folder aliasing feature, that was introduced in windows vista (though I don't recall the windows name for the feature and I am running win7), I believe to be the problem. For example, if I share and mount  C:\Users I have access to C:\Users\myuser and can create folders and documents there. However the predefined folders Music, Documents, Pictures I have no write permission inside of.
    Next if I share and mount C:\Users\myuser I have the same result for those folders however now I can see additional folders  one is 'My Documents' in this folder I have write access and changes are mapped back to the Documents Folder. Additionally there are now showing in the Documents folder, I had no write access to, additional folders which also weren't showing before 'My Music', 'My Pictures', and 'My Videos' in which I now have write access and they map back as well.
    When I connected to the shares from an XP machine I could simply access the original folders.

  • [Solved] Mounting Windows Share

    Well what a 2nd post this is!
    I've just spent forever trying not to have to post for help but its time i do.
    I'm trying to mount a windows share on bootup in autostart.sh so that mpd doesn't die via not being able to find the tunes.
    It seams you HAVE to be root to do this. Yes sudo will work but you don't get a password prompt.
    I've only found one useful thread from google but these solutions don't seam to work for me http://bbs.archlinux.org/viewtopic.php?pid=272495
    [dan@z0r ~]$ mount /mnt/shares/tank_d
    mount: only root can mount //10.1.1.69/d$ on /mnt/shares/tank_d
    Last edited by DanWA (2008-12-14 06:54:35)

    Don't try and mount it at GUI start, mount it with all the other drives when your system starts. Put it in your /etc/fstab file so that it mounts at system boot - no password required.
    Something similar to below. See the fstab link for exact details:
    /dev/xxxx /mnt/shares/tank_d ntfs auto,user,rw 0 0
    Bob
    Last edited by Hrod beraht (2008-12-13 15:53:39)

  • Mount windows share in linux

    How can i mount a windows share in read-write mode from my linux system
    I am able to mount in readonly mode as below even though i mentioned rw in that.
    mount -t cifs -o username=administrator,password=adminpass,rw,0,0 //192.168.1.1/RHEL5 /mnt/win
    This post is related to Re: backup strategy

    I managed to make it work.
    I did entry as below in /etc/fstab
    //192.168.1.1/RHEL5 /mnt/win cifs credentials=/etc/
    smbcred 0 0
    run
    mount -a
    /etc/smbcred file contains username and password
    now it is mounted as read write mode.
    ~

  • Lost a lot of files during move to a mounted Windows share via SMB

    Hi,
    after mounting a network Windows share via SMB and then using the Finder to move files from my local disk to that share all the files that were to be moved are lost in ****. I am totally upset because these were very important files. What is it that drives 10.5.2 nuts here? Has anybody any ideas?

    Look in \Music\iTunes\iTunes media\ (or \iTunes music\).

  • Auto-mounting Windows shares at login?

    When I bring my PowerBook to work, there are five different Windows shares I need to connect to in order to access all my files. I've added the shares to my Login Items under my account in System Preferences, so they connect automatically every time I log in.
    The only problem is that this opens a separate Finder window for each connection. I'd like to just have it connect to the shares in the background without opening any new windows. Is there any way to do this? I tried checking the "hide" checkbox in Login Items, but it didn't make a difference.

    I discovered a better solution - if you make an Automator action (get specified servers > connect to servers), it won't open any new Finder windows.
    So I created the action, filled it in with the 5 servers I need to connect to, saved it as an application, and added it to my login items. Now when I log in, I just get a dialog for each server asking for my username/password, and it connects to each in the background without opening any windows.

  • [SOLVED] mounted windows shares from fstab dont stay mounted

    i have windows shares mounted through fstab and when i first boot up, they are mounted fine, but after a certain amount of time (not sure how long it takes) they disappear and it hangs thunar (oh yeah, using xfce) and i have to reboot to get them back. running mount -a doesnt bring them back
    line from fstab
    //charger/share /home/user/Documents cifs rw,uid=1000,gid=1000,file_mode=0700,dir_mode=0700,credentials=/home/credfile 0 0
    daemons line from rc.conf
    DAEMONS=(hwclock syslog-ng hal network netfs samba @alsa crond)
    Last edited by dodgefan (2011-08-03 20:01:44)

    thanks anyway, figured it out, installed autofs and setup everything to mount to /media and made links to my home folder

  • Check for mounted DFS share with exists in apple script

    OS: OSX Mountain lion.
    Can any one advise how to detect if a DFS share is mounted or not?
    I have been using the following code:
    set volumeLabel to "R$"
    tell application "Finder"
      exists disk volumeLabel
    end tell
    Which works fine with a normal SMB shares or attached hard drives but I cant get it to work with a DFS Share, it always returns false (see attached screen shot.
    Also tried:
    if volumeLabel is in (do shell script "/bin/ls Volumes") then
              return true
    else
              return false
    end if
    Which didnt work with a DFS Share aswell.
    Any help appreciated.
    Cheers,
    Richard

    Hi,
    Since you're checking to see if a value exists in the Desktop key, you can do something along these lines:
    If (Get-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name SCRNSAVE.EXE -ErrorAction SilentlyContinue) {
    Write-Output 'Value exists'
    } Else {
    Write-Output 'Value DOES NOT exist'
    EDIT: Sam, what version of PowerShell are you running? Your code doesn't seem to work for me on v4:
    PS C:\> Push-Location
    Set-Location "HKCU:\Control Panel"
    $Result = Test-Path -Path ".\desktop\SCRNSAVE.EXE"
    Pop-Location
    $Result
    False
    Don't retire TechNet! -
    (Don't give up yet - 12,950+ strong and growing)

  • AppleScript to mount network share & launch application fails on computers

    Hi All,
    I am trying to write a script that I can place in the dock that will perform two actions. The first action is to mount a sharepoint, the second is to launch an application.
    I have been very successful at doing this on my iMac (Intel). The script works under any user.
    However, I have a lab of 26 Mac Minis (Intel) and the script won't work!!
    Here's my script (it's simple!):
    tell application "Finder"
    mount volume "afp://ok-xserve-01.mpcsd.org/Apps" as user name "[user]" with password "[password]"
    end tell
    launch application "Type To Learn 3"
    Of course, I replace the items in brackets with their appropriate values.
    I save the script as an application. When I try to run it on any of the Mac Minis, I get the following error message:
    '"afp://ok-xserve-01.mpcsd.org/Apps" doesn't understand the <<event aevtmvol>> message'
    I've tried it w/o "as user..." and also in the form of "afp://user:pass@server/share" but all returns the error message above.
    I even logged in as the user on one of the lab computers, created the script, and it ran! As soon as I logged off and logged back in, it stopped working.
    These systems, along with my iMac, are bound to an Open Directory & Active Directory, and authenticate via Active Directory.
    I can log in as the lab user on my iMac, and the script will work every time I launch it. It'll work as any user on my iMac.
    Any ideas? If you need more info let me know!
    Thanks!!

    Try putting in the command "delay 30" before the other lines. It delays the script for 30 secs...OSX needs to load before running the script

  • Smb mount Windows share 10.6.8 vs 10.8.4

    We have the following setup:
    a windows file share
    an iMac with 10.6.8 connected to active directory
    a MBpro with 10.8.4 connected to active directory
    logged into each machine w/ the same user
    The 10.6.8 smb mounts (via Finder->Connect to server) to the file share as one would expect.
    The 10.8.4 smb mount fails with an error message:
    Error mesage: The foler "foldername" can't be opened because you don't have permission to see it's contents.
    Here's what I've done:
    checked the smb mount path and they are the same on both machines
    mounted the folder on a windows machine
    So, it seems that user permission is OK because it works on the 10.6.8 and windows machines.
    Any ideas why it's failing on the 10.8.4?
    Thanks!!!

    Welcome to Apple Communities
    1. Open Disk Utility and repair permissions
    2. Open Finder, go to your user's folder > Library > Caches and delete everything
    3. Verify disk
    4. See if your apps are compatible with OS X 10.8 > http://www.roaringapps.com
    You can also do a backup and create a DVD or USB drive to install OS X > http://arstechnica.com/apple/2012/07/how-to-create-a-bootable-backup-mountain-li on-install-disk/ When you start in 10.8 installer, open Disk Utility, select your volume and erase the drive, and install

  • Applescript for mounting Sharepoints

    Hi Guys,
    I need some advice. We are trying to mount our student's sharepoints onto their desktop when they login with their AD accounts. I've done a bit of AS to get the points to mount:
    set user_name to do shell script "whoami"
    set the_server to "Our Server IP"
    set volume1 to {"Art Student/s2009/"}
    set volume2 to {"Art Student/s2008/"}
    tell application "Finder"
    delay 0.3
    repeat with i from 1 to number of items in the volume1
    set the_volume to item i of the volume1
    repeat 1 times
    if (list disks) contains the_volume then exit repeat
    try
    mount volume "afp://" & user_name & "@" & the_server & "/" & volume1 & user_name & ""
    on error
    display dialog "Sorry " & user_name & " you cannot access this " & volume1 & " as you may not have access.
    end try
    end repeat
    end repeat
    end tell
    tell application "Finder"
    delay 0.3
    repeat with i from 1 to number of items in the volume2
    set the_volume to item i of the volume2
    repeat 1 times
    if (list disks) contains the_volume then exit repeat
    try
    mount volume "afp://" & user_name & "@" & the_server & "/" & volume2 & user_name & ""
    on error
    display dialog "Sorry " & user_name & " you cannot access this " & volume2 & " as you may not have access.
    end try
    end repeat
    end repeat
    end tell
    The problem I'm having is when a student is in just folder it comes up with a connection failed message whenever it cannot find a student's folder.
    Is there anyway way I can stop the connection failed message coming up at all??

    You might want to try this assuming that your AFP server is part of the kerberos domain:
    try
    mount volume "afp://;AUTH=Client Krb [email protected]/ShareName"
    end try
    That will allow the use of the Kerberos TGT to request a service ticket and you will not need to query for logged in user name. You can still turn the ShareName into a list variable and then iterate through it in a loop.
    Again, this will only work if your OS X Server is also joined to the AD domain and AFP is properly "kerberized." Oh, or if you are using ExtremeZ-IP it should work also. If you are using Services for Macintosh, well, then my condolences.
    Hope this helps

  • [SOLVED] advanced shell script for mount and unmount samba share

    Good morning guys,
    Today I've a very long question....
    Hope in your help....:
    I usually move from different network.
    For one of those I need to mount some share that are under an ActiveDirectory server.
    To do that I use samba.
    Especially I've made and use the below  shell script.
    I know that it's so stupid but I'm a very newbie:
    #!/bin/sh
    echo "This is a custom script for mount my citrix share"
    echo "Please insert user password (must a sudoer user)"
    echo " "
    sudo mount -t cifs -o username='myusername',password='mypassword' //host_ip/TsHome$/myusername /home/myuser/samba_share/TsHOME
    sudo mount -t cifs -o username='myusername',password='mypassword' "//host_ip/direction" /home/myuser/samba_share/direction
    echo " "
    read -p "Press ENTER key to close this terminal"
    exit
    As I say the script work but it's so crude...!
    I want/need to implement it whit the follow addictions:
    1. print a feedback on mount: somenthing like "TsHOME is now mounted" or "unable to mount TsHOME"
    2. check if the share are already mounted: to prevent accidentally multiple mount. If a share is already mounted I want to print something like "TsHOME is already mounted on /home/myuser/samba_share/TsHOME"
    3. ask for share password  (now it's in clear on script) - This is optinal
    4. un-mount the share before reboot or shutdown command. That because I've notice that If i reboot or shutdown without manually un-mount the share the step of unmounting network file system became very slow
    If it's no extremely difficult, can someone help me to write this script?
    I know that man exist but I'm not a programmer and it's so difficult for me approch it.
    Thank you in advance.
    Ale
    Last edited by Alexbit (2010-09-23 21:29:13)

    Thank you very (VERY) much!
    I've follow your information and.. it work!
    If can be usefull to other this is the complete script:
    #!/bin/sh
    echo "This is a custom script for mount citrix share"
    echo "****************************************"
    echo " "
    echo "Please insert domain password:"
    read -s mypassword
    echo " "
    echo "|checking mount state...in share are not mounted mount it!|"
    echo "+-------------------------------------------------------------------------+"
    if grep "TsHome" /etc/mtab &>/dev/null; then
    grep "TsHome" /etc/mtab | awk '{print "TsHome is already mounted on " $2}'
    else
    sudo mount -t cifs -o username='yourusername',password="$mypassword" //ipaddress/TsHome$ /home/Samba_share/TsHOME && echo "TsHOME is now mounted" || echo "unable to mount TsHOME"
    fi
    echo " "
    if grep "direction" /etc/mtab &>/dev/null; then
    grep "direction" /etc/mtab | awk '{print "direction is already mounted on " $2}'
    else
    sudo mount -t cifs -o username='yourusername',password="$mypassword" '//ipaddress/direction' /home/Samba_share/direction' && echo "direction pat is now mounted" || echo "unable to mount direction"
    fi
    echo " "
    if grep "Area" /etc/mtab &>/dev/null; then
    grep "Area" /etc/mtab | awk '{print "Area is already mounted on " $2}'
    else
    sudo mount -t cifs -o username='yourusername',password="$mypassword" '//ipaddress/Area' /home/Samba_share/Area && echo "Area is now mounted" || echo "unable to mount Area"
    fi
    echo " "
    echo "All DONE!"
    echo " "
    read -p "Press ENTER key to close this terminal"
    exit
    I don't really well understand what I've to put in rc.local.shutdown....
    I think somethings like:
    #!/bin/bash
    # /etc/rc.local.shutdown: Local shutdown script.
    echo "This is a custom script for UN-mount citrix share"
    echo "********************************************"
    echo " "
    echo "|check mount state: if mount then un-mount!|"
    echo "+-------------------------------------------------------+"
    echo " "
    if grep "TsHome" /etc/mtab &>/dev/null; then
    grep "TsHome" /etc/mtab | awk '{print "TsHome is NOT mounted -> going on..." $2}'
    else
    sudo umount /home/Samba_share/TsHOME && echo "TsHOME is now UN mounted" || echo "unable to UN-mount TsHOME"
    fi
    echo " "
    if grep "direction" /etc/mtab &>/dev/null; then
    grep "direction" /etc/mtab | awk '{print "direction is NOT mounted -> going on.." $2}'
    else
    sudo umount /home/Samba_share/direction && echo "direction is now UN mounted" || echo "unable to UN-mount direction pat"
    fi
    echo " "
    if grep "Area" /etc/mtab &>/dev/null; then
    grep "Area" /etc/mtab | awk '{print "Area is NOT mounted - Finished" $2}'
    else
    sudo umount /home/Samba_share/Area && echo "Area is now UN mounted" || echo "unable to UN-mount Area"
    fi
    echo " "
    echo "going shutdown"
    echo " "
    sleep 5
    I've try but it seems to ignore the IF statement... this is the output when ALL share are UNmounted:
    $ sh /etc/rc.local.shutdown
    This is a custom script for UN-mount citrix share
    |check mount state: if mount then un-mount!|
    +-------------------------------------------------------+
    umount: /home/Samba_share/TsHOME: not mounted
    unable to UN-mount TsHOME
    umount: /home/Samba_share/direction: not mounted
    unable to UN-mount direction
    umount: /home/Samba_share/Area: not mounted
    unable to UN-mount Area
    going shutdown
    Tomorrow I will test again when I'm at office.
    Meanwhile can you check if I made a macroscopic mistakes?
    Thank you again!
    Last edited by Alexbit (2010-09-23 17:34:49)

Maybe you are looking for

  • Can Apple replace my macbook pro (mid 2012) retina's battery if I think that the battery health has gone bad/in need of and renewal?

    Can Apple replace my macbook pro (mid 2012) retina's battery if I think that the battery health has gone bad/in need of and renewal??? I've had my Macbook for about 11 months now and i use it every day; its gone though about 420 cycles of charging an

  • F110 - Posting orders: 8 generated, 7 completed

    Hi, One of our payment in a payment run was not completed. In payment log, payment document was generated and there were no errors.  But in FB03 or table BKPF, there is no such document number. In other words, a document number was skipped. I checked

  • HT1721 My images in iphoto '11 are not sharp unless I zoom in

    Before upgrading to iPhoto '11 from '09 my images looked good, but now they appear soft until I zoom in. The whole point of digital photography is to view your images in there best possible way. How can I get the images to look better when viewing in

  • Connecting to Outlook Global Address List

    I have an application which needs to email the contents of a record to one or more people in our Outlook Global Address List. I would like to present the user with the GAL so he/she may pick the recipient. Anybody done this?

  • Commit after delete

    I have a job that process data for last 7 days. Most of data(90%) is processed in first iteration(first day) after what i delete processed data and do a commit. What is strange is that job continues to work slow as if there is same amount of data lik