Connect to servers with Applescript using Keychain

Feb 02, '05 09:06:00AM

Contributed by: jason mark

I've been using Quicksilver for a while, and it's great, but unfortunately, it doesn't successfully resolve aliases to servers. I found various AppleScripts online which connect to a server, but none appear to use the keychain, forcing me to log in every time. I came up with a solution which uses an AppleScript to call an alias (located in my Favorites folder) to open a share using the Keychain password. I imagine that other people who have struggled with getting AppleScript to open shares might find this useful also.

Here's the script:

set thePath to ((get path to startup disk) & "Users:" & ¬
 (do shell script "echo $USER") & ¬
 ":Library:Favorites:ALIAS to Server") as string

tell application "Finder"
  open alias thePath
  activate
end tell
Note that this script also shows a simple way to open files in a given user's home directory. Everything I had found online (including some hints here) pointed out that there's not easy way to do this -- but by using a shell script to get the $USER setting, it's relatively simple from there. To use the generic version, just replace ":Library:Favorites:ALIAS to Server" in the first line with the path to the folder you need to reach.

[robg adds: I haven't tested this one...]

Comments (15)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050131160112998