I’ve got a script that converts a Windows path on a local server to an smb:// one and puts it in the clipboard, e.g.
“P:\Wibble\Blah” becomes “smb://mylocalserver/Projects/Wibble/Blah”
I now want to automate the following:
- Open Finder
- Press CMD + K (“Connect to Server”)
- Press Enter
I’ve looked at “open location” but nothing seems to happen. Do I need to mount? What’s the best way to open an SMB path in Finder automatically?
Any help greatly appreciated.
First of all, mounting file systems is done by the kernel and not by the finder. So to automatically mount a volume you should read mount_smb before starting with this but a command could like like this:
do shell script "mkdir /Volumes/public && mount -t smbfs //guest:@myserver/PUBLIC /Volumes/public"
you can use umount or diskutil to unmount the volume.
Wow, thanks for the quick response. Dumb question:
If I open an SMB path using the method I described (CMD + K in Finder) am I mounting the location?
What I meant is that the Finder will mount the volume using the same smbfs library as the mount command in the shell, so why not doing it yourself? Both are identical except that the Finder will popup a window and select a file when given in the URL.
I would quite like Finder to appear with the relevant folder open. I anticipate that the paths being converted are for specific files but I don’t want to go as far as trying to open the files - just take the user to the point where they can decide for themselves.
If you just use that mount command, with your parmeters inside it, and use the folder name you intend to use, (I’ll continue to use public, so you get the hang of it).
I have amended the command, so that once you execute it, a new window with the open smb folder will appear in Finder.
do shell script "mkdir /Volumes/public && mount -t smbfs //guest:@myserver/PUBLIC /Volumes/public ; cd /Volumes/public ; open ."