Profile for favorite servers

bpavlov
Honored Contributor

I made this into a profile using MCXtoProfile. Testing on OS X 10.9.5. The JSS is not involved yet.

<?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>favoriteservers</key>
    <dict>
        <key>Controller</key>
        <string>CustomListItems</string>
        <key>CustomListItems</key>
        <array>
            <dict>
                <key>Name</key>
                <string>smb://server1.fqdn/</string>
                <key>URL</key>
                <string>smb://server1.fqdn/</string>
            </dict>
            <dict>
                <key>Name</key>
                <string>smb://server2.fqdn/</string>
                <key>URL</key>
                <string>smb://server2.fqdn/</string>
            </dict>
            <dict>
                <key>Name</key>
                <string>afp://server3.fqdn/</string>
                <key>URL</key>
                <string>afp://server3.fqdn/</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>

Tried scripting additions of servers as well using the following as well:

#!/bin/bash

/usr/bin/defaults write com.apple.sidebarlists favoriteservers -dict Controller CustomListItems CustomListItems '( { Name = "afp://server1.fdqn/"; URL = "afp://server1.fdqn/"; }, { Name = "smb://server2.fdqn/"; URL = "smb://server2.fdqn/"; }, { Name = "smb://server3.fdqn/"; URL = "smb://server3.fdqn/"; } )'
killall cfprefsd
killall cfprefsd
killall cfprefsd

exit 0

The script at the very least creates the plist but doesn't populate the favorite servers like I want it to. Tried killing Finder as well, but that didn't do much either. Restarting the computer does work, but I don't want to have people restart for something that really shouldn't require a reboot.

I've checked out a few threads but none seem to mention what needs to be killed for the plist to take effect right away. Ideally the profile would just work but that's not happening. How are others approaching this?

7 REPLIES 7

jacob_salmela
Contributor II

I use a script to do this:

#!/bin/bash
bud='/usr/libexec/Plistbuddy'
plist=$HOME'/Library/Preferences/com.apple.sidebarlists.plist'

servers=('afp://servername'
'smb://servername'
'vnc://servername'
'ftp://servername')

killall cfprefsd
echo "Setting servers for $plist"
echo "Removing previous entries..."
${bud} -c "Delete favoriteservers" ${plist}

echo "Creating new list..."
${bud} -c "Add favoriteservers:Controller string CustomListItems" ${plist}
${bud} -c "Add favoriteservers:CustomListItems array" ${plist}

for i in "${!servers[@]}"
do
    echo "Adding to Favorite Servers: ${servers[$i]}..."
    ${bud} -c "Add favoriteservers:CustomListItems:$i:Name string ${servers[$i]}" ${plist}
    ${bud} -c "Add favoriteservers:CustomListItems:$i:URL string ${servers[$i]}" ${plist}
done

echo "Finalizing settings..."
killall cfprefsd
defaults read ${plist} favoriteservers > /dev/null

bpavlov
Honored Contributor

@jacob_salmela I tried that and that didn't work either. The issue doesn't seem to be in generating the plist as your script does that just fine. Mine does as well. However the preference is not being read right away. What does it take to get the preference to apply right away? Perhaps I'm not waiting long enough though. How long do you wait until the preference is readable? Or is a restart/logout the only way?

P.S. I really need to learn python so that I can just interact with CoreFoundation Preferences directly. :(

mm2270
Legendary Contributor III

You're not the only one that has struggled to get the change to com.apple.sidebarlists to be recognized short of logging out/in or rebooting. I ran into this myself here:
https://jamfnation.jamfsoftware.com/discussion.html?id=5010

And here's another non JAMFNation thread that also discusses it. No-one there was able to identify which service or background process controls that either:
http://apple.stackexchange.com/questions/160273/finder-sidebarlist-wont-update-after-changing

Its possible its controlled by loginwindow, but I think killing that would log you off in a rather unceremonious way, so that's not recommended :)

Not sure what to tell you other than that its not an easy one to figure out.
But, I have to assume something is updating that on the fly since if you add a server to the list in the GUI it shows up there immediately!

bpavlov
Honored Contributor

For some fun, I also killed loginwindow but that did not work. In fact when I logged back in, the plist file got overwritten.

mm2270
Legendary Contributor III

Yikes! That's odd, but I suppose not entirely unexpected since killing loginwindow does a very abrupt logoff, so it may not be caching the change to the plist when its done that way. Maybe it just gets re-read from the previous cache upon login again?... although my understanding in how cfprefsd works is that it re-reads any relevant pref files when logging in again from disk into memory, so I'm not sure that even explains it.
I wish I knew what managed that preference setting, but it has eluded me for a long while now. Just not sure what the heck controls that.

bpavlov
Honored Contributor

I did an opensnoop -f ~/Library/com.apple.siderbarlists.plist while editing the favorite servers list through the GUI and got this as a result:

  UID    PID COMM          FD PATH                 
  501    549 SFLSharedPrefsT   4 /Users/user/Library/Preferences/com.apple.sidebarlists.plist 
  501    549 SFLSharedPrefsT   4 /Users/user/Library/Preferences/com.apple.sidebarlists.plist 
  501    475 Finder         5 /Users/user/Library/Preferences/com.apple.sidebarlists.plist 
    0     60 mds           11 /Users/user/Library/Preferences/com.apple.sidebarlists.plist

So I went ahead and added killall Finder to my original script. It kills Finder which means all windows you have open will close but it does re-open them.

It's a little jarring to say the least but it does work. The only problem with my script is that it overwrites the favorite servers, but I can fix that with -dict-add so that it only adds and doesn't overwrite. Although I'll leave that up to my manager to decide.

#!/bin/bash

killall cfprefsd
/usr/bin/defaults write com.apple.sidebarlists favoriteservers -dict Controller CustomListItems CustomListItems '( { Name = "afp://server1.fdqn/"; URL = "afp://server1.fdqn/"; }, { Name = "smb://server2.fdqn/"; URL = "smb://server2.fdqn/"; }, { Name = "smb://server3.fdqn/"; URL = "smb://server3.fdqn/"; } )'
killall cfprefsd
killall cfprefsd
killall Finder

exit 0

And yes, I needed to kill cfprefsd 2 times (may need to do it 3 times for safe measure). Like I said it's very jarring and you will get the spinning beach ball for 5 seconds while Finder relaunches.

I don't know that I'm going to deploy this though.

mm2270
Legendary Contributor III

Hmm, interesting. Though I haven't been able to reproduce it for myself. Doesn't seem to matter how many killalls I do on Finder, cfprefsd or anything else, in any order that makes the changes show up. Not that I care all that much since its not something I need to actually do. Just one of those nagging things. :)

I would agree with you though that a) a Configuration Profile should just apply this automatically, and b) probably not the best thing to deploy this as it stands.
Re: config profile not working, that could just be an inconsistency with them, or, the fact that Apple doesn't have a built in way of adding favorite servers with profiles that I'm aware of. I guess they never intended for them to be managed or manipulated other than by the user.