Network-Userfolder a the Dock

ds_support
New Contributor III

Hello Community, Again!

I need a solution for the Network-Userfolder / Adding Server. The User Folder / Share Folder is mounted automatically and works. The problem is, after I lost the network connection or starting the Macbook without Ethernet I get a Questionmark in the Dock. I attached a Screenschot.

I am looking for a script. If one or twice smb server are not mounted, they mount them and kill the dock. The workaround is at the moment, to connect to server manually and kill the dock, then it works.

Maybe everyone can help me.

Many Thanks for help!
Christian89ba98c37be648c389f2e7b302b7a5e3

1 ACCEPTED SOLUTION

pat_best
Contributor III

I am using an app I built in automator to mount the user home folder and a launchagent that runs it at login to make sure it is that user that is referenced for everything. It isn't very elegant and will not check if the mount is present if someone disconnects it. The mount part is written in Applescript and is part of the built in templates of automator, but here is the embedded script :

-------------------------------

--- User Information

-- Get the logged in users username set loggedInUser to do shell script "whoami" -- Get the Users account UniqueID set accountType to do shell script "dscl . -read /Users/" & loggedInUser & " | grep UniqueID | cut -c 11-" -- Get the nodeName from the Users account set nodeName to do shell script "dscl . -read /Users/" & loggedInUser & " | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-" -- Get the Users group membership from AD set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & " | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'" -- Get the Users AD Home Folder set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 10- | sed 's/\\/\//g' " -- Checks to see if account is an AD Account, if its not exit if accountType is less than 1000 then tell me to quit end if

--- Drives

--Home Folder -- Maps the drive specified in the profile field for the AD User continue if user has no profile path set try mount volume "smb:" & ADHome on error end try -- Restart the dock --------- tell application "Dock" quit end tell

and here is the launchagent:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.nethome.mount</string>
    <key>Program</key>
    <string>/Library/Application Support/JAMF/Repository/homefolder.app/Contents/MacOS/applet</string>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

I had to make sure that the built in AD plugin home folder mount was not part of the binding or I ended up with two dock items (one was a question mark) for the user network home folder. Note that this is installed in the root Library folder and not the user library. I am thinking a combination of this and your mount checking script might take you the direction you want to go.

Can someone make this pretty? :)

View solution in original post

3 REPLIES 3

ds_support
New Contributor III

Hello,

I get a solution. The following script checked the connection to the Network Home Folder, if it is not connected, he reconnect them.

I try to enter the command line "killall -kill Dock" after the mounting process but it don't works... How I can kill the dock process after mounting?

#!/bin/sh

# Create a log writing function
writelog()
{
    echo "${1}"   
}

writelog "STARTING: User drive mount"

# Already mounted check

# The following checks confirm whether the user's personal network drive is already mounted,
# (exiting if it is).  If it is not already mounted, it checks if there is a mount point
# already in /Volumes.  If there is, it is deleted.

isMounted=`mount | grep -c "/Volumes/$3"`

if [ $isMounted -ne 0 ] ; then
    writelog "Network share already mounted for $3"
    exit 0
fi

# Mount network home
writelog "Retrieving SMBHome attribute for $3"

# Get Domain from full structure, cut the name and remove space.
ShortDomainName=`dscl /Active Directory/ -read . | grep SubNodes | sed 's|SubNodes: ||g'`

# Find the user's SMBHome attribue, strip the leading \ and swap the remaining  in the path to /
# The result is to turn smbhome: \server.domain.compath	ohome into server.domain.com/path/to/home
adHome=$(dscl /Active Directory/$ShortDomainName/All Domains -read /Users/$USER SMBHome | sed 's|SMBHome:||g' | sed 's/^[\]*//' | sed 's:\:/:g' | sed 's/ ////g' | tr -d '
' | sed 's/ /%20/g')

# Next we perform a quick check to make sure that the SMBHome attribute is populated
case "$adHome" in 
 "" ) 
    writelog "ERROR: ${3}'s SMBHome attribute does not have a value set.  Exiting script."
    exit 1  ;;
 * ) 
    writelog "Active Directory users SMBHome attribute identified as $adHome"
    ;;
esac

# Mount the network home
    mount_script=`/usr/bin/osascript > /dev/null << EOT
#   tell application "Finder" 
#   activate
    mount volume "smb://${adHome}"
#   end tell
EOT`


writelog "Script completed"
# Script End

exit 0

Many Thanks
Christian

pat_best
Contributor III

I might be wrong, but I think that the killall -kill Dock command when run from the JSS looks for the root dock and won't kill the logged in user's dock. I am trying to find my set up for this....

pat_best
Contributor III

I am using an app I built in automator to mount the user home folder and a launchagent that runs it at login to make sure it is that user that is referenced for everything. It isn't very elegant and will not check if the mount is present if someone disconnects it. The mount part is written in Applescript and is part of the built in templates of automator, but here is the embedded script :

-------------------------------

--- User Information

-- Get the logged in users username set loggedInUser to do shell script "whoami" -- Get the Users account UniqueID set accountType to do shell script "dscl . -read /Users/" & loggedInUser & " | grep UniqueID | cut -c 11-" -- Get the nodeName from the Users account set nodeName to do shell script "dscl . -read /Users/" & loggedInUser & " | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-" -- Get the Users group membership from AD set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & " | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'" -- Get the Users AD Home Folder set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 10- | sed 's/\\/\//g' " -- Checks to see if account is an AD Account, if its not exit if accountType is less than 1000 then tell me to quit end if

--- Drives

--Home Folder -- Maps the drive specified in the profile field for the AD User continue if user has no profile path set try mount volume "smb:" & ADHome on error end try -- Restart the dock --------- tell application "Dock" quit end tell

and here is the launchagent:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.nethome.mount</string>
    <key>Program</key>
    <string>/Library/Application Support/JAMF/Repository/homefolder.app/Contents/MacOS/applet</string>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

I had to make sure that the built in AD plugin home folder mount was not part of the binding or I ended up with two dock items (one was a question mark) for the user network home folder. Note that this is installed in the root Library folder and not the user library. I am thinking a combination of this and your mount checking script might take you the direction you want to go.

Can someone make this pretty? :)