Applescript for Mapping Network Drives

If you have multiple mac users connected to an Active Directory domain and are trying to use Microsoft's file sharing protocol, SMB, this script may be of service.

1.) Open Script Editor from the Applications folder
2.) Enter the script as follows:
tell application "Finder"
      set dialog_1 to display dialog "Please enter your username:" default answer "username"
      set user_name to the text returned of dialog_1
set net_share to "smb://domain;" & user_name & "@server.FQDN.com/" & user_name & ""
mount volume net_share
end tell

3.) Replace server.FQDN.com with the server you want to map to
4.) replace " & user_name & " with the share you want to map to; here I am just mapping to a share named for the user who is connecting
5.) Save as an application then launch to test
6.) The user will be prompted for the password

***You can also pull the user's username from the system like so:

set user_name to system attribute "USER"

***it is safer to do it this way then adding an additional line such as:

set dialog_2 to display dialog "Please enter your password:" default answer "" with hidden answer
set the pass_word to the text returned of dialog_2

as a password entered in this method that contains certain special characters like @ or / will result in an error as they are interpreted as part of the server string and not the password.

Comments

Popular Posts