Finder Sidebar Settings Using Configuration Profiles

shalford
New Contributor

I was wondering if there is a way that I can manage what my users see on the Finder Sidebar without using manage preferences. I tried to custom settings using an edited plist file but this did not work. Any help would be greatly appreciated.

33 REPLIES 33

ptrondsen
New Contributor

You need use an app called mcxtoprofile, it will convert your sidebar.plist to a configuration profile.
Then you can load the configuration profile to get your favorite servers.

https://github.com/timsutton/mcxToProfile

davidacland
Honored Contributor II

Hi, config profiles are ok until you start getting to paths like user home directories (and other sub-directories). If you create a profile based on one user, the paths are absolute and won't work for others.

Have a look at https://github.com/matt4836/changeSidebarLists/blob/master/Change_Sidebar_List.py

tuinte
Contributor III

Hey, David. Is that script meant to run once (i.e., at imaging time) to effectively augment the user template, or is it running once per user at time of sign-in? Or running at every login? Where exactly am I adding/removing the options I'd like? The information under the Help menu appears to give the syntax I'm supposed to use, but where am I putting it? Any help is appreciated. I have no experience with Python and very little with scripting in general. If you think use of the script is beyond the scope of such a noob, is there maybe a resource you can link to that might give me a better idea on how to make use of such a script (even the basics, like how do I download the script from that site - or is it a copy-and-paste deal)?

Thanks for any help in advance.

davidacland
Honored Contributor II

Hi @tuinte,

The script is designed to be run once per user so it can take the name of the logging in user and use that in the commands.

For example, to use the script to add the logging in user's home folder to the sidebar you would use this:

Change_Sidebar_List.py first file:///Users/$USER

Unfortunately the sidebar is a particularly difficult preference file to manage any other way.

tuinte
Contributor III

OK, so I'm assuming I would use that not as something to paste into the script, but instead as a Terminal command to launch the script, and then the script uses "first file:///Users/$USER" to fill that entry into the sidebar. So if I'm looking to add a few things to the sidebar, I'd call the script multiple times. Correct? And I believe I can call the script using a LaunchAgent, so it runs at login. So add a LaunchAgent plist to run the script multiple times at login to add all the items I want, in addition to a script at the end to delete the LaunchAgent plist so it doesn't run at future logins.

Is that the broad idea? Forgive me if this is embarrassingly easy.

davidacland
Honored Contributor II

Thats it. The script doesn't need modifying so you could drop it on to the clients in somewhere like /usr/bin. Then you use a script something like:

#!/bin/sh
Change_Sidebar_List.py first file:///Users/$USER
Change_Sidebar_List.py first file:///Users/$USER/Documents
Change_Sidebar_List.py first file:///Users/$USER/Desktop
Change_Sidebar_List.py first file:///Users/$USER/Movies
exit 0

There's no harm in having it run multiple times as each finder item can only be added once. That being said, you are right, it would be best to make sure it doesn't keep running at every login so either delete the launchagent or use a Casper policy set to run once per user.

matt4836
Contributor II

It has been awhile since I looked at this since I wrote it, but I believe there is a HOMEDIR variable to simplify things.

Look at the help to see some usages.

Change_Sidebar_List.py help

Change_Sidebar_List.py after /Applications Downloads Add Applications after Downloads
Change_Sidebar_List.py first HOMEDIR Add the user's Home Directory first in the list
Change_Sidebar_List.py last HOMEDIR/Music Add the user's Music Directory last in the list

tuinte
Contributor III

Thank you both, @davidacland and @matt4836. I'm getting close, I think. I've got it working if I set the CASPER_MODE to False and run via Terminal, but when running through a Casper login policy I'm getting:

Script result: Traceback (most recent call last):
File "/usr/bin/Finder_Sidebar.py", line 44, in 
if sys.argv > 3 and CASPER_MODE: sys.argv[3] = CURRENT_FINDER_USERNAME
IndexError: list assignment index out of range

I've set CASPER_MODE to True for that one, and the permissions on the script (in /usr/bin) are 755.

Any ideas? I really am grateful.

EDIT: I might mention I'm just copying the code in the link above and pasting it into TextWrangler and saving. Don't see an actual download button on the git page. Don't know if that might be a factor. Formatting looks identical to me.

matt4836
Contributor II

did you set variables in the Policy? are you running this as a login policy?

tuinte
Contributor III

Thanks, @matt4836.

A login policy is running this script:

#!/bin/sh

/usr/bin/Finder_Sidebar.py last HOMEDIR

exit 0

matt4836
Contributor II

Ah, there is your problem, since you are technically not running the script as a policy, you need to set Casper Mode to False.

When you a run a script in a policy it passes three variables (Mount point, Computer Name, User Name). The script compensates for that when in Casper Mode.

If the script is already deployed, you can update your script by changing it to:

#!/bin/sh
CURRENT_FINDER_USER=`ls -l /dev/console | awk '{ print $3 }'`
COMPUTER_NAME=`hostname`
/usr/bin/Finder_Sidebar.py '/' "$COMPUTER_NAME" "$CURRENT_FINDER_USER" last HOMEDIR

exit 0

tuinte
Contributor III

Gotcha. Totally get it now (well, mostly - not the entirety of the code itself, but high level). Got it working.

Hmm... This has been a wonderful learning experience for implementing scripts in general. Thank you kindly. Tip coming. Beer on me.

matt4836
Contributor II

Thank you! That is why we are here. If you need more assistance, create a new thread and tag me.

apizz
Valued Contributor

Thanks for this @matt4836 and @tuinte.

So I made an issue for myself by creating a sidebar package from Composer and then filling user templates (I know, foolish mistake, but this IS my first go around ...). We've already imaged over 100 machines, so I'm trying to remediate and also establish a default for all our users when they login for the first time. The script I'm testing with is below. I'm trying to get the order of sidebar items to match the order I've listed them below. I'm also copying the Python script locally to the computer to /usr/bin to then run the local script via another script (pasted below) which is activated at login via a policy:

#!/usr/bin/python
/usr/bin/Change_Sidebar_List.py first file:///Users/$USER/Desktop
/usr/bin/Change_Sidebar_List.py first file:///Users/$USER
/usr/bin/Change_Sidebar_List.py first file:///Volumes/VolumeName/'Middle School Faculty'/$USER
/usr/bin/Change_Sidebar_List.py first file:///Users/$USER/Documents
/usr/bin/Change_Sidebar_List.py first file:///Users/$USER/Downloads
exit 0

Just wanted to double-check that since I'm copying the Python script locally, Casper Mode in the Python script should be set to FALSE ...

This is going a bit further, but I'm wondering if my network volume path will work. When each user logs in their network sharepoint mounts automatically.

Thanks in advance!

apizz
Valued Contributor

I'm running the Python script (Casper Mode is FALSE) via Terminal and as a test I'm trying to create shortcut to a network volume sharepoint at the following path:

/Volumes/Administration/

So this is what I enter in Terminal:

python /usr/bin/Change_Finder_Sidebar.py first file:///Volumes/Administration/

However, when I run it, it gives me this: Always use a full path when adding an Item. It should start with a forward slash, for example /Applications

Unless I'm missing something, aren't I already specifying the full path ... Any thoughts? I'm running OS X 10.10.4

davidacland
Honored Contributor II

You just need to use /usr/bin/Change_Finder_Sidebar.py first /Volumes/Administration/

apizz
Valued Contributor

Ahhhh. I see now. Thanks @davidacland! I was going off the path that was listed when I did the list command on the Python script. Works like a CHARM!

Thanks all for helping to make my life as a very new Casper Admin easier!

anverhousseini
Contributor II

How do I remove "All My Files", "iCloud Drive" and "AirDrop"?

I tried it with following:

/usr/local/bin/changefinderfavorites.py remove HOMEDIR/iCloud Drive
/usr/local/bin/changefinderfavorites.py remove HOMEDIR/AirDrop
/usr/local/bin/changefinderfavorites.py remove HOMEDIR/All My Files

But seems not to work. Any hint?
Thanks!

davidacland
Honored Contributor II

Hi,

I think the python script is only intended for custom items. The ones you've mentioned should be manageable with a standard defaults write or config profile.

Have a look in the sidebarlists preference file and there should be some keys that match.

plawrence
Contributor II

@matt4836 I've been looking at your script as a way to modify the Sidebar in OS X 10.11, but there appears to be an issue with the LaunchServices function being deprecated in the latest OS? It was posted on your GitHub here.

I tried just changing the 'import' line from LaunchServices to SharedFileList, but then I get an error "No module named SharedFileList". Is there a simple way to make your script compatible with 10.11?

applesoftware
New Contributor

Hi @anverhousseini

Try

/usr/local/bin/changefinderfavorites.py remove "All My Files"
/usr/local/bin/changefinderfavorites.py remove "iCloud"
/usr/local/bin/changefinderfavorites.py remove "AirDrop"

Hope that helps!

anverhousseini
Contributor II

Hi @PlymUni

This doesn't work. Sometimes the scripts remove iCloud, then All My Files and every time AirDrop. One item stays every time.

Hi @davidacland

No chance to change the sidebar plist. Any idea?

anverhousseini
Contributor II

Got the script working with that:

/usr/local/bin/changefinderfavorites.py remove HOMEDIR/"All My Files"
/usr/local/bin/changefinderfavorites.py remove HOMEDIR/"iCloud"
/usr/local/bin/changefinderfavorites.py remove HOMEDIR/"AirDrop"

jacopo_pulici
Contributor

Anyone had luck setting the Finder's sidebar on OS X 10.11 El Capitan?

plawrence
Contributor II

@Jachk I ended up using a script called mysides to modify the sidebar on first login, see https://jamfnation.jamfsoftware.com/discussion.html?id=17204

jacopo_pulici
Contributor

Thanks @plawrence, that worked!
:)

apizz
Valued Contributor

Haven't messed with El Capitan yet, but given the most recent comments on this thread, does this mean the ChangeFinderSidebar python script no longer works? Related to the addition of SIP in El Capitan?

davidacland
Honored Contributor II

Not sure on the cause as the python errors I get with changesidebarlists doesn't seem to point in that direction.

I've been testing out mysides over the past few days and it works great in 10.11.

kstrick
Contributor III

I think ChangeFinderSidebar doesn't work because of the API changes in El Cap.... some of the launchservices calls were moved

perrycj
Contributor III

@davidacland Were you able to remove AirDrop with mysides?

I can remove iCloud Drive and add the user home folder with no issue but AirDrop remains. This is what I've been using:

#!/bin/sh

mysides=/usr/local/bin/mysides

$mysides remove AirDrop file:///Users/$3/AirDrop
$mysides remove iCloud Drive file:///Users/$3/iCloud Drive
$mysides add $3 file:///Users/$3

davidacland
Honored Contributor II

Hi,

To remove Airdrop the syntax is a little different: mysides remove domain-AirDrop

perrycj
Contributor III

@davidacland That did it. Thank you kind sir.

ACummins
New Contributor

Has anyone got this working with 10.12.6??