Wednesday 28 August 2013

AppleScript: Mount Drive / Connect to Server with Choose from List

I have written a script to mount drive / connect to server which you can select the drives that you would like to mount or the servers that you would like to connect from a list.


AppleScript:
property server_list : {{name:"SMB", address:"smb://UK;User1@test.uk.local", volume:"User1"}, ¬
      {name:"AFP", address:"afp://test.uk.local/", volume:"User2"}, ¬
      {name:"SMB", address:"smb://UK;User3@test.uk.local", volume:"User3"}}

tell application "Finder"
      try
             eject disk "share"
      end try
end tell

set display_list to {}
repeat with the_item in server_list
      set display_list to display_list & name of the_item
end repeat


set choice to choose from list display_list with title "Mount Drive " with prompt "Please select your name to mount your drive" with multiple selections allowed
if result is false then return

if choice is not {} then
      repeat with the_name in choice
             repeat with the_server in server_list
                  
                   if (name of the_server) is equal to the_name as string then
                          try
                                tell application "Finder"
                                      set x to mount volume (address of the_server & "/" & volume of the_server)
                                      log address of the_server
                                      display dialog "You have mounted your drive successfully. Click OK to exit." with title "Mount Drive" with icon note buttons {"OK"} default button 1
                                      return
                                end tell
                          end try
                          return
                   end if
             end repeat
            
      end repeat

end if

No comments:

Post a Comment