views:

49

answers:

3

Is there an Coca/obj-C API call to mimic the "Connect to Server" action in Finder? It's possible with Automater, so it seems like Finder has a hook somewhere.

+1  A: 

This might not be the best way, but can't you just use mount?

Paul Betts
For a remote server (like `smb://`)? I'm pretty sure `mount` is for local devices only.
eduffy
Works on Linux at least - you specify it as //server.name/share/path/to/folder
Paul Betts
+2  A: 

An easy way is to just run some applescript code. I'll show you 2 choices. This first one is the standard way to show that Finder window from applescript.

NSString* cmd = @"choose URL";

The resulting window is bare-bones though, so you can actually open the Finder's window with this command...

NSString* cmd = @"tell application \"Finder\" to activate\ndelay 0.2\ntell aplication \"System Events\" to keystroke \"k\" using command down";

After choosing either of the "cmd" strings, you can execute that applescript code with this...

NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:cmd];
[theScript executeAndReturnError:nil];
[theScript release];
regulus6633
+1  A: 

Turns out there's an old Carbon function (can't find a Cocoa equivalent) called FSMountServerVolumeSync which does what I was looking for. You can supply and smb:// URL and login credentials.

File Manager Reference

OSStatus FSMountServerVolumeSync (
  CFURLRef url,
  CFURLRef mountDir,
  CFStringRef user,
  CFStringRef password,
  FSVolumeRefNum *mountedVolumeRefNum,
  OptionBits flags
);
eduffy