AppleScripting Windows drives on Mac OS X?

Sunday 18 July 2004This is more than 20 years old. Be careful.

Today I’ve been hacking AppleScript to make it easier for my wife to back up her work from her Mac to our Windows box. Despite all the English-like syntax, I managed to make a new folder on the Windows drive with the date in the name, and copy her important folder into it. But I’m stumped on how to get the Windows drive connected in the first place.

When I use the Record command in Script Editor, and then manually connect the drive, I get code like this:

set target of Finder window 1 to item "Network"
set target of Finder window 1 to folder "MyStreet" of item "Network" of startup disk
set target of Finder window 1 to disk "C"
set target of Finder window 1 to folder "sue" of disk "C"

I’m willing to leave aside the odd repetitive nature of these lines (why does line 2 redo what was done on line 1?) When I run this code while the network drive is already connected, it works fine. But if I run it when the drive is disconnected (which is when I need it), it fails at the third line, which is just where the UI pops up a box title “SMB Mount”.

Does anyone know how to do this? Searching Google is proving fruitless. Help!

Comments

[gravatar]
On OS X, due to it's unix heritage, remote SMB drives need to be mounted using mount_smbfs before the finder layer can see it. Take a look at man mount_smbfs.
[gravatar]
Turns out it's as simple as:

mount volume "smb://computer/drive"

though I couldn't find any mention of the command in the Finder applescript dictionary!

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.