Connect to server list and com.apple.sidebarlists.plist

Sonic84
Contributor III

Hello, I wrote a script to add a users corporate shares to their "connect to servers" list in Mac OS X (Finder --> Go --> Connect to Server...). This script writes directly to ~/Library/Preferences/com.apple.sidebarlists.plist. I'm having trouble getting Finder to recognize that changes have been made to this plist. Rebooting the system displays the new servers in the list just fine. However logout/login and relaunching Finder does not.

Has anyone run into this and is there a solution to get the list to update without a reboot?

Thank you!

Thank you!

9 REPLIES 9

Chris
Valued Contributor

Is this a Mavericks-only issue?
Which command are you using to modify the plist?

mm2270
Legendary Contributor III

I remember dealing with this type of scenario way back on this older thread-
https://jamfnation.jamfsoftware.com/discussion.html?id=5010

Back then, like now, I don't know what controls that plist being loaded into the user session, although back when I worked on it, a log out and log in did the trick. If a full reboot is now needed, it would be cool to figure out some other way to get it recognized. I've tried restarting Finder, SystemUIServer and some other services and nothing has done the trick. Just not sure what controls that. I'm wondering if its a user level launchd job?

peineke
New Contributor III

If you are still on Casper v8 you can just use MCX preferences to do this, it works great.

If you are on v9 you lose the ability to do this with MCX preferences so we ended up using an applescript app that just mounts the servers.

Lotusshaney
Contributor II

Under 10.9 plist's are cached and as such a copy won't work. Have a Look at my blog here

http://blog.designed79.co.uk/?p=1761

Sonic84
Contributor III

Hello, thank you for the feedback. @Chris I'm using Defaults write and sed to modify a copy of the plist then moving it into place with mv. @peineke I can see how MCX would work for a static list, however each user has a unique server list.
@Lotusshaney Unfortunately re-reading the completed plist did not refresh the server list with the contents of the plist. Neither did killing cfprefsd.

Here is the chunk from the script that injects the new list into a copy of com.apple.sidebarlists.plist. I intend to post the whole script to github when done.

# ...
    cp "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: The users com.apple.sidebarlists.plist could not be backed up. Aborting...."
        exitfunction
    else
        echo "$(date): com.apple.sidebarlists.plist was backed up."
    fi  

    defaults delete "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist" favoriteservers
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not remove favoriteservers from com.apple.sidebarlists.mod.plist. Aborting...."
        exitfunction
    else
        echo "$(date): Favoriteservers was removed from com.apple.sidebarlists.plist."
    fi  

    defaults write "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist" favoriteservers -dict Controller CustomListItems CustomListItems REPLACEME
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not add favoriteservers to com.apple.sidebarlists.mod.plist. Aborting...."
        exitfunction
    else
        echo "$(date): Favoriteservers was re-added to com.apple.sidebarlists.plist with placeholder."
    fi  

    plutil -convert xml1 "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not convert com.apple.sidebarlists.mod.plist to XML1 format. Aborting...."
        exitfunction
    else
        echo "$(date): com.apple.sidebarlists.mod.plist was successfully converted to XML1."
    fi  

    sed -i "" "/ *<string>REPLACEME</string>/r $tempfile5" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"

    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not inject new server list. Aborting...."
        exitfunction
    else
        echo "$(date): New server list was injected into com.apple.sidebarlists.mod.plist."
    fi  

    sed -i "" 's/ *<string>REPLACEME</string>//g' "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not remove placeholder tag in com.apple.sidebarlists.mod.plist. Aborting...."
        exitfunction
    else
        echo "$(date): Placeholder tag was removed from com.apple.sidebarlists.mod.plist."
    fi  

    plutil -convert binary1 "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not convert com.apple.sidebarlists.mod.plist into binary format. Aborting...."
        exitfunction
    else
        echo "$(date):com.apple.sidebarlists.mod.plist was successfully converted into binary1."
    fi

    plutil -lint "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR: Could not validate com.apple.sidebarlists.mod.plist. Aborting...."
        exitfunction
    else
        echo "$(date):com.apple.sidebarlists.mod.plist was successfully verified as a valid XML file."
    fi  

    mv "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist.old"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR:  com.apple.sidebarlists.plist could not be moved. Aborting...."
        exitfunction
    else
        echo "$(date):com.apple.sidebarlists.mod.plist was successfully renamed to com.apple.sidebarlists.plist.old."
    fi  

    mv "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist"
    if [[ "$?"  != 0 ]]; then
        echo "$(date):ERROR:  apple.sidebar.mod.plist could not be moved. Aborting...."
        mv "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist.old"  "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist"
        echo "$(date):ERROR:  com.apple.sidebarlists.plist plist restored from backup"
        exitfunction
    else
        echo "$(date):com.apple.sidebarlists.mod.plist was successfully renamed to com.apple.sidebarlists.plist.old."
    fi  

# ....

dstranathan
Valued Contributor II

Sorry to wake a dead thread, but Im curious as to how are you all managing "Connect to Server" (SMB file server URL shortcuts) in High Sierra.

We are modifying our storage and new shortcuts will be required. I have Jamf Policies & login scripts in place for automating the process, but there are unique situations when end-users needs to mount the SMB file server manually.

I considered creating & deploying a folder containing various inet.loc files, but this is messy (and sometimes they "break" when macOS tries to open them in apps other than Finder, etc)

Is there no longer way to deploy & manage server shortcuts? I can't be the only person wrestling this topic...?

mm2270
Legendary Contributor III

There used to be a nice tool that Apple introduced in El Capitan called sfltool (See this thread on it) that let you programmatically add in Connect to Server shortcuts. But apparently it worked too well, and Apple has an issue about allowing us to have nice things*, so it was completely neutered to the point of uselessness in Sierra, and remains as so in High Sierra.

That being said, at the very end of the link I posted above to the sfltool thread, someone posted a python script that can generate the plist file for the Connect to Server connections. You might find it useful. I haven't tried it myself. At this point, 3rd party utilities or scripts like that one might be our only option because Apple refuses to give us a way to do it natively.

* Half joking and half serious. But Apple really seems to have some kind of unresolved conflict about Mac admins having useful tools and automation processes. They sometimes really don't want us to have those at our disposal and make stupid decisions to kill them, like in this case.

dstranathan
Valued Contributor II

I have been using the "usual weapons of choice" such as defaults, plistbuddy and sfltool in the past, but alas they are indeed broken in recent macOS updates.

After more investigation, I found a possible Python solution by @korylprince here: [https://www.jamf.com/jamf-nation/discussions/20218/the-slftool-thread#responseChild166114](link URL)

francksartori
New Contributor III

Hi.
I'm using a quick and (very very) dirty solution to manage the favorite servers list.
The idea is to create the plist the old way it was with previous systems (using receipe found on Internet and probably right here).
When the new item does not exist, the Finder reads the old fashioned plist to build it, like in a process of upgrade.
The only caveat is that I need to delete the new item so it is recreated from the old fashioned plist (each time the list has to be rebuilt).
And new favorite servers the user may have saved between two builds are lost.
Anyway, in the context of my customer, that was ok. Quick and not costly. I hope that better may be done.
Best regards.
Franck