Mac – Mounting Network Shares via Applescript

Recently, I had to create a /Library/LaunchAgents job that would mount network shares upon a user logging in. I had the job run an AppleScript (don’t hate me) to do this, and I picked up several tips:

If you need to get some information from the currently logged in user, use “system info”, and avoid using “do shell script”

tell application "Finder"

set userName to get short user name of (system info)

end tell

Prefix the FQDN of the mount with the user’s short name. While this seems unnecessary, I found that it dramatically sped up my script, and stopped NetAuthAgent from crashing every time my script ran on 10.6.8.

tell application "Finder"

set userName to get short user name of (system info)
mount volume "afp://" & userName & "@server.fqdn.here"

end tell

Lastly, as you can see from the example above, use “mount volume” instead of “open location”. The reason being is that “mount volume” will not open up a window once the share has been mounted, which is usually what you want.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s