Skip to main content

Hey all,

I'm currently testing out dockutil as my resource for creating a dock for both students and faculty. So far I've been able to add everything that I need with the exception of a user's home folder. When a user (both student and faculty) signs in, the dock should display their networked home folder on the right side of the dock. Does anyone have (or know of) a script that checks the user's account information and based on who signs in, adjust the dock to add the correct folder?

Thanks!

Here's what I'm using that does what you're looking for. This is just a snippet from a larger script.

#!/bin/bash

#Define variables
user=$3
memberOf=`id -G -n $3 | tr '[:upper:]' '[:lower:]'`
SMBHome=smb:`dscl . read /Users/$3 SMBHome | cut -d' ' -f2 | tr '\\' '/'`

#Function to check membership and create dock URL's
function create_url_items {
/usr/local/bin/dockutil --add /Users/$user/Downloads --label 'Downloads' --position beginning --sort dateadded --no-restart /Users/$user
echo "Added Downloads"
/usr/local/bin/dockutil --add /Users/$user/Documents --label 'Documents' --position beginning --sort name --no-restart /Users/$user
echo "Added Documents"
/usr/local/bin/dockutil --add $SMBHome --label 'Network Docs' --position beginning --no-restart /Users/$user
echo "Added Network Docs"
}

#Delete existing dock items
/usr/local/bin/dockutil --remove all /Users/$user

#Add new dock items
create_url_items

echo $user " is a member of the following groups:"
echo $memberOf

exit 0

This is almost exactly what I'm looking for; however, the network folder is within a series of other folders. The script should run like this:

A user (let's say he's a freshman in 1 of 2 high schools in my district) logs in. The script should then be able to say "Using this users AD username, mount the user's folder from the <insert high school name> folder, and within the <insert graduating year of student> folder within the network share drive.

Is there even a way to script this?


You could add something like this:

if [[ $memberOf =~ "abc students" ]];then
    /usr/local/bin/dockutil --add smb://$server1/share/abc/$user --label 'Network Docs' --position end --no-restart /Users/$user
fi

You'd obviously need an if statement like this in your script for every school and/or grade.


The problem I have with dockutil is adding shares via the address adds as a web clip rather than a folder. I've tried adding the share via using the mounted share name at /Volumes, however, it won't reconnect back to that share when logging back in. The only way I've found to add a network share to the dock with the same functionality as dragging the share to the dock is adding a dock item via a policy or via the jamf command line program. I'm trying to figure a way to script this w/o knowing the package id.


Doesn't the AD plugin do this by checking the option for: "Use UNC path from Active Directory to derive network home location."

That's been adding the logged in user's AD assigned network home folder to the dock for us.


We have that option checked off, so by default when a user logs in, it will map that folder based on what is set in AD. However, removing all the dock items (which is the first entry in my script) removes that folder from the dock.

I guess my next question is: if AD binding is set to use the UNC path by default, what would be the correct way to script it to re-add it to the end of my dock?


Bumping this post.

I've got my dock exactly how I want it now, with the exception of the home folder. After looking into this, I've found that our user's home folder is set within AD. At this point, all I would need is a script that would pull that specific information from AD (based on the user), and add that Home Directory onto the end of my dock (the scripts used above only produced errors, or a question mark where the Home Directory should be).

Any help would be greatly appreciated.


I've not tested it but a possible idea.

If you run a script that mounts the user's home, then runs DockUtil and adds "/Volumes/[user's mounted home]" how does that work out?

I know it's not ideal but it might be the best bet.

Darren


I tried this and I get an error that says com.apple.dock.plist is not a home folder or a plist file. has anyone seen this. I too want to put mounted drives on the dock for my mobile users. @daz_dar @cbrewer


Hi @wmateo

Could you post the exact command you are running so we can see where the error may be?

Thanks

Darren


Thanks for responding @daz_dar This is the verbose output of my script. I have the drives mounted on the desktop

bash-3.2$ sudo sh -v /Users/wmateo/Desktop/Dock.sh -v

!/bin/bash

Define variables

user=$3
memberOf=id -G -n $3 | tr '[:upper:]' '[:lower:]'
id -G -n $3 | tr '[:upper:]' '[:lower:]'
SMBHome=smb:dscl . read /Users/$3 SMBHome | cut -d' ' -f2 | tr '' '/'
dscl . read /Users/$3 SMBHome | cut -d' ' -f2 | tr '' '/'

Function to check membership and create dock URL's

function create_url_items {
/Library/Application Support/JAMF/dockutil.py --add $SMBHome --label 'My Home Folder' --position beginning --no-restart /Users/$user
}

Add new dock items

create_url_items
/Users/Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist

exit 0


Try it like this...

#!/bin/bash

#Define variables

user=$3
memberOf=`id -G -n $3 | tr '[:upper:]' '[:lower:]'`
SMBHome=smb:`dscl . read /Users/$3 SMBHome | cut -d' ' -f2 | tr '\\' '/'`

#Function to check membership and create dock URL's

function create_url_items {
su -l $user -c "/Library/Application Support/JAMF/dockutil.py --add $SMBHome --label 'My Home Folder' --position beginning --no-restart"
}

#Add new dock items
create_url_items

exit 0

This is what I get when I run above script. @cbrewer

/Users/wmateo/Desktop/Dock.sh: line 3: Define: command not found
/Users/wmateo/Desktop/Dock.sh: line 6: -G: command not found
wheel daemon kmem sys tty operator procview procmod everyone staff certusers localaccounts admin com.apple.sharepoint.group.1 com.apple.sharepoint.group.2 _appstore _lpadmin _lpoperator _developer com.apple.access_screensharing
/usr/bin/read: line 4: builtin: dock.sh: not a shell builtin
dsRecTypeStandard:Users
su: illegal option -- c


Sounds like the copy/paste didn't work for you. If the script is trying to run "Define" it means the # didn't get retained. Its commented out in the script @cbrewer posted, so something didn't translate correctly.


@mm2270 I picked that up after I posted this. I still get the "su: illegal option -- c" any ideas?


@PaGuarnieri were you able to successfully implement this in your enviroment? if so would you mind sharing sample script?


Hi @wmateo

Are you running this as a Casper login policy or just in terminal?

If you're running this on terminal then the $3 variable isn't being passed through.

It should work in Casper as-is (when run as a login policy script) but if you're testing it in terminal you'll need to substitute $3 for $USER (all caps)

Hope that helps!

Darren


Hey @wmateo

Unfortunately, after a number of failed runs with the script, we've decided not to use it. Good luck on figuring this out.

~Paul