Script to Mount AD H: Drive

jshipman
New Contributor III

Hello Wonderful JAMF nation!!

I am really needing some help with a script that I have written to Mount the network home Directories. The script works, but I am needing there to be a persistent alias of that network share either on the Desktop or on the Dock. What can I add to the end of the script that would make it work?

Thanks!!

set username to do shell script "whoami"
set pass to ""
set network_share1 to ""
set domain to "mckinneyisd.local"
set server to ""
set sharedirectory to ""
set network_share2 to "home_dir"
set categoryOne to ""
set staff to ""

if sharedirectory is "" then set dialog_2 to display dialog "Please enter 6 Digit ID:" default answer "" set the sharedirectory to the text returned of dialog_2
end if

if pass is "" then set dialog_1 to display dialog "Please enter First Name:" default answer "" set pass to text returned of dialog_1 set categoryOne to the first character of pass
end if

if categoryOne is "A" then set server to "filprt01" set staff to "staff01"
end if

if categoryOne is "B" then set server to "filprt01" set staff to "staff01"
end if

if categoryOne is "C" then set server to "filprt01" set staff to "staff02"
end if

if categoryOne is "D" then set server to "filprt01" set staff to "staff02"
end if

if categoryOne is "E" then set server to "filprt02" set staff to "staff03"
end if

if categoryOne is "F" then set server to "filprt02" set staff to "staff03"
end if

if categoryOne is "G" then set server to "filprt02" set staff to "staff03"
end if

if categoryOne is "H" then set server to "filprt02" set staff to "staff03"
end if

if categoryOne is "I" then set server to "filprt02" set staff to "staff03"
end if

if categoryOne is "J" then set server to "filprt02" set staff to "staff04"
end if

if categoryOne is "K" then set server to "filprt03" set staff to "staff05"
end if

if categoryOne is "L" then set server to "filprt03" set staff to "staff05"
end if

if categoryOne is "M" then set server to "filprt03" set staff to "staff06"
end if

if categoryOne is "N" then set server to "filprt03" set staff to "staff06"
end if

if categoryOne is "O" then set server to "filprt03" set staff to "staff06"
end if

if categoryOne is "P" then set server to "filprt03" set staff to "staff06"
end if

if categoryOne is "Q" then set server to "filprt03" set staff to "staff06"
end if

if categoryOne is "R" then set server to "filprt04" set staff to "staff07"
end if

if categoryOne is "S" then set server to "filprt04" set staff to "staff07"
end if

if categoryOne is "T" then set server to "filprt04" set staff to "staff08"
end if

if categoryOne is "U" then set server to "filprt04" set staff to "staff08"
end if

if categoryOne is "V" then set server to "filprt04" set staff to "staff08"
end if

if categoryOne is "W" then set server to "filprt04" set staff to "staff08"
end if

if categoryOne is "X" then set server to "filprt04" set staff to "staff08"
end if

if categoryOne is "Y" then set server to "filprt04" set staff to "staff08"
end if

if categoryOne is "Z" then set server to "filprt04" set staff to "staff08"
end if

set network_share1 to "smb://" & server & "." & domain & "/" & network_share2 & "/" & staff & "/" & sharedirectory

mount volume network_share1

tell application "Finder"

open location "smb://" & server & "." & domain & "/" & network_share2 & "/" & staff & "/" & sharedirectory

end tell

7 REPLIES 7

tsd25108
New Contributor II

Try this:

do shell script "ln -s /Volumes/WhateverYourVolumeNameIs /Users/$3/Desktop/WhateverYouWantTheLinkToBeNamed"

jshipman
New Contributor III

The problem is that the WhateverYourVolumeNameIs is different for every user. i.e. Volume/Network_Folder/Staff/IndividualUserName

russeller
Contributor III

I also created an apple script to mount the Home Drive for AD users. Here is a snippet from my AppleScript that handles some errors and opening a new Finder window of their Home Drive when they click on the AppleScript from the Dock. I saved the AppleScript as an application and put it in their dock via Casper. Hopefully this will help:

if exists disk "homes$" then
        try
            make new Finder window to folder username of disk "homes$"
            set current view of Finder window 1 to list view
        on error
            beep
            set question to display dialog "Your district Home Folder (H: Drive) cannot be found at this time. You can try forcing the share to disconnect and relaunching the application to see if that helps. Otherwise, click the 'Submit HelpDesk Ticket' button below to report this issue." buttons {"Cancel", "Force Disconnect Share", "Submit HelpDesk Ticket"} default button 1 with icon stop
            set answer to button returned of question
            if answer is equal to "Submit HelpDesk Ticket" then
                tell application "Safari" to activate
                tell application "Safari" to make new document with properties {URL:"http://URLtoHelpDeskWebsite.com/"}
            else if answer is equal to "Force Disconnect Share" then
                do shell script "umount -f /Volumes/homes$"
                display dialog ¬
                    "The Share has been disconnected, please try launching the application again." buttons {"Okay"} default button 1 with icon caution
            end if
        end try
        return
    end if

tsd25108
New Contributor II

@jshipman - the $3 variable that JAMF uses by default for usernames should fix that then.

mm2270
Legendary Contributor III

Jessie, you should be able to simplify your script a bit by combining the checks for the first letter into groupings. Instead of using:

if categoryOne is "A" then
    set server to "filprt01"
    set staff to "staff01"
end if

if categoryOne is "B" then
    set server to "filprt01"
    set staff to "staff01"
end if

Combine them like this:

if categoryOne is "A" or categoryOne is "B" then
    set server to "filprt01"
    set staff to "staff01"
end if

Because either A or B is using the same share. Do the same for the rest of the letters and you'll be able to cut it down from 26 separate if/then blocks to about 8 or so from what I can see. There's probably even a way to make it simpler yet, but I don't know for sure.

Matt
Valued Contributor

Doesn't the built in AD tool do this if you have home folders declared in Active Directory? I know in our environment I can set the home folder location in AD and then its in my dock when I log on.

sean
Valued Contributor

Each AD user record could have something like:

/Users/[username]

or if you have them elsewhere, for example

/Volumes/Users/[username]

With the later, clearly you need to make sure that the mac can mount this. The automounter can take care of this for you. Check out the man page on auto_master, you could even use the auto_home and wildcards. Check out the following for more info:

http://rajeev.name/2007/11/22/autofs-goodness-in-apples-leopard-105-part-i/

As for the script, rather than all of the if statements, try case instead.

Here is an example. Change the variable 'myVar' to be different values and you'll see what is going on. (Try A through to D and then anything else)

myVar=A

case $myVar in
    [A-B])
        echo "A or B"
        ;;
    C)
        echo "C"
        ;;
    *)
        echo "other"
        ;;
esac