Create Apple Script to Map SMB Shares with custom servers

857 views Asked by At

I want to make a applescript that will let the user type in the server name and name of the shared folder and map it via applescript. I know how to map a set in stone smb share but I want this to be user friendly so they can they type in the share name. Example smb://share3/installs The script would ask what server is it on: share3 Script would ask what is the folder name: installs Then the script would popup the default connect to server logon info that the user needs to type.

1

There are 1 answers

0
John Christopher Jones On

Well, what you're asking for is display dialog and a bit of do shell script, which is detailed in the AppleScript Language Guide (PDF).

So, to answer your question directly, you probably want something like the following:

set server to text returned of (display dialog "Type the name of the server" with title "Open Share" default answer "10.0.10.50")

set share to text returned of (display dialog "Type the name of the share" with title "Open Share" default answer "installs")

do shell script "open smb://" & server & "/" & share

However, if your users are "simple" as you say, then you might not want them typing in server names and share names. Instead, you could provide them with pick lists.

set serverShares to {{"share2", {"installA", "installB"}}, {"share3", {"install1", "install2"}}}

set serverList to {}
repeat with servers in serverShares
    set the end of serverList to item 1 of servers
end repeat

set serverChoice to item 1 of (choose from list serverList with title "Open Shared Volume")

set shareList to {}
repeat with i from 1 to length of serverShares
    set server to item 1 of item i of serverShares
    if server is equal to serverChoice then
        set shareList to item 2 of item i of serverShares
        exit repeat
    end if
end repeat

set shareChoice to item 1 of (choose from list shareList with title "Open Shared Volume")

do shell script "open smb://" & serverChoice & "/" & shareChoice

Just customize the server/share name nested list at the top to customize which shares are available on which servers. Using the shell script open smb://server/share will prompt the user for login credentials if they don't already have them saved in their keychain.