views:

739

answers:

2

I have a bash script which will be run on a Mac via ssh. The script requires a particular network drive to already be mounted. On the Mac, I mount this drive by opening a folder "JPLemme" on that drive in Finder. This mounts the drive until the Mac goes to sleep at night.

Obviously, Finder isn't available via ssh, so I want to create an AppleScript that will simulate what I do through the GUI. I've tried:

tell application "Finder"
activate
open "JPLemme"
end tell

I receive the following error:

execution error: Finder got an error: Can't get "JPLemme". (-1728)

I assume I'm missing something obvious, but Google has failed me. I would also be willing to entertain better solutions like mounting the drive directly; I've avoided that approach because I don't want the Mac to choke trying to mount the drive a second time after I've already mounted it in an unexpected way. (I don't really like Macs or AppleScript...)

+2  A: 

Your network volume should have a domain attached to it of some kind. So, "JPLemme.domain.com". I use the following chunk of code to get onto a network volume that is password protected:

    tell application "Finder"
       try
          set theServer to mount volume "smb://path/to/volume" as username "YourUserName" with password "YourPassword" 
--Please note here that this is a plain string without any built-in security. Use at your own risk.
       on error
          set VolumeCount to (get count of disks)
          repeat with x from 1 to VolumeCount
             set thisVolume to disk x
             if name of thisVolume is "JPLemme" then
                set theServer to thisVolume
                exit repeat
             end if
          end repeat
       end try
    end tell

You can clean it up as necessary, but that's the core of it. Good luck

Philip Regan
+1  A: 

At it's very core, all that is really needed is the following:

Tell Application "Finder"
   Mount Volume "smb://username:password@server/sub/directory"
End Tell

But what is used will depend largely on network environment and errors returned.

Philip Regan