Connect To Server Address

kmitnick
New Contributor III
New Contributor III

I'd like all users to have the servers that they need to connect to populate under the "Go>Connect To Server" menu

Is there a way to do this with the JSS?

Any help would be greatly appreciated.

Thanks

13 REPLIES 13

mm2270
Legendary Contributor III

Back in the day those were stored as separate favorites files in the user's /Library/Favorites/ location. As of 10.6 and higher though they now get stored in the com.apple.sidebarlists.plist file, in the user Library/Preferences folder.

You could script something out using PlistBuddy to write those values into the plist file, but, if you're talking about newly imaged machines, it might be easier to just create the plist on a fresh system, grab a copy of it and bring it into Composer to package up as a DMG and then push it with the FEU and FUT options.
If you're concerned about overwriting existing files though you'd have to work on scripting that in I think.

In case you want to poke around to locate the saved servers, open the plist with a text editor like TextWrangler or even TextEdit and search for "favoriteservers" to find the line where they start.

As an alternative option to all that, you can place weblocs or shortcuts to the servers they need to access on their Desktop, Dock or other locations.

kmitnick
New Contributor III
New Contributor III

MM2270,

I appreciate your quick reply. I was already going the composer route and using FUT. For some reason, it was not working.

I also appreciate your other suggestions and will give them a try.

Thanks!

kitzy
Contributor III

Does anyone know if it's possible to do this with a defaults write command? We've been trying to get it to work but so far haven't been successful.

tcam
Contributor

I push this out through defaults template. But yah the user can go back in and change it.

kitzy
Contributor III

We're not all that worried about the user changing it. Can you give more info on how you do it? We just can't get it working...

tcam
Contributor

I create an account and configure how I want the side bar, connect to server list, show external volumes. Then I copy it to the defaults template.

ie:
sudo ditto /Users/sourceAccount/Library/Preferences/com.apple.sidebarlists.plist /System/Library/User Template/*/Library/Preferences/com.apple.sidebarlists.plist
sudo chown -R root:wheel /System/Library/User Template/
sudo chmod -R -N /System/Library/User Template/

that way, when the user logs in for the first time, the account is created with my sidebar plist.

kitzy
Contributor III

Ahh, yeah. We need a more surgical approach. Users already have their machines, and a former admin had them connecting to the servier via an IP instead of a DNS name (I know, I know). We just had to change their IP schema so we want to push out the settings to everyone. I don't want to mess with people's Finder sidebars though.

mm2270
Legendary Contributor III

John, I know of a way to add them in programmatically or even change existing entries with PlistBuddy, but I won't be able to write anything up until later this evening. It's possible to do though without deploying a file.

kitzy
Contributor III

I would greatly appreciate the help! I'd love to get it pushed out over the weekend so when everyone comes in on Monday they're ready to rock.

mm2270
Legendary Contributor III

I'm finally getting around to this. Hopefully this will get you with enough time to work something out over the weekend.

So, the plist you're looking to change is located in the user's home directory at ~/library/Preferences/com.apple.sidebarlists.plist
That plist file has an array in it called 'favoriteservers' which is why you need to use PlistBuddy to manipulate it. Defaults won't cut it for this. For each numbered 'dict' entry for a saved server, there are 2 values, 'Name' and 'URL' These can be the same thing and usually are when someone just clicks the "+" button in the Connect to Server window. But the name can be something more descriptive too if you want. URL obviously is the address for the server.

If I wanted to add a new server shortcut entry into my own com.apple.sidebarlist.plist, I would run commands like the following:

# Create the dict entry in the 'favoriteservers' array
/usr/libexec/PlistBuddy -c "Add :favoriteservers:CustomListItems:0 dict" ~/Library/Preferences/com.apple.sidebarlists.plist
# Add a 'Name' entry to the dict we just created
/usr/libexec/PlistBuddy -c "Add :favoriteservers:CustomListItems:0:Name string MyShare" ~/Library/Preferences/com.apple.sidebarlists.plist
# Add a 'URL' entry to the dict we created in the first step
/usr/libexec/PlistBuddy -c "Add :favoriteservers:CustomListItems:0:URL string afp://myservername/MyShare/" ~/Library/Preferences/com.apple.sidebarlists.plist

That's the basic idea. Putting this together a little more, if we want to affect the logged in user's plist file, we can do this:

#!/bin/sh

PLB="/usr/libexec/PlistBuddy"
userAccount=$( who | awk '/console/{ print $1 }' )
userPlist="/Users/$userAccount/Library/Preferences/com.apple.sidebarlists.plist"
theName="MyShare"
theURL="afp://myserver/MyShare/"

## Add the new server entry for current logged in user
"$PLB" -c "Add :favoriteservers:CustomListItems:0 dict" "$userPlist"
"$PLB" -c "Add :favoriteservers:CustomListItems:0:Name string $theName" "$userPlist"
"$PLB" -c "Add :favoriteservers:CustomListItems:0:URL string $theURL" "$userPlist"

One thing with this that I've seen is it doesn't seem to show up in Connect to Server until a logout/login. I suspect there is something that needs to get unloaded and reloaded in order for the window to get properly updated, but I'm not sure what it is. I had tried killing the Finder but that doesn't do it, so something else controls that.

If you needed to add multiple entries, you can either just repeat the above steps as many times as needed, or write up a loop in the script that would cycle through the values you supply it with.

For changing existing entries, you have to use "Set" instead of "Add" in the command, but the trickier part is knowing which item in the array to change. In the above, by using "0" for the entry, its adding a new one at the top and pushing all the others down the list. Existing entries may not be at position 0, because it all depends on how many favorites a user has added and when.
You can get the count of of the items in the array with something like this. you have to minus one from the line count because the array starts at 0, not 1, so using the line count as is would not be accurate:

arrayCount=$( expr $( "$PLB" -c "Print :favoriteservers:CustomListItems" "$userPlist" | grep URL | wc -l  ) - 1 )

But from here you'd have to loop over them one by one checking for the address or URL you want to change, with something like this:

for i in $( eval echo {0..$arrayCount} ); do
    if [[ $( "$PLB" -c "Print :favoriteservers:CustomListItems:$i" "$userPlist" | grep "afp://192.168.1.1" ) != "" ]]; then
        echo "Found the entry. Changing URL to DNS name"
        ## Change the entry from IP to DNS
        "$PLB" -c "Set :favoriteservers:CustomListItems:$i:URL afp://server.company.com/share" "$userPlist"
    fi
done

I'll leave the rest to you to go from here. I haven't thoroughly tested any of this, but I did run them once or twice as I was writing this up and they seemed to work, so hopefully this will help.

kitzy
Contributor III

Thanks! That got us to where we needed to be.

One word of caution for anyone else:

userAccount=$( who | awk '/console/{ print $1 }' )

This will return a list of all logged in users, and the script doesn't work quite right when more than one user is returned. In our environment, this wasn't an issue as each machine only has 1 user, but it's something to be aware of.

themacdweeb
Contributor

we get around the issue of multiple users being logged in by scoping out a variable based on UID, not name. so our script leverages that and cycles through the users one at a time. also, a fine note from the always-awesome rich trouton to remember to change the ownership of the files as jamf runs as root (http://derflounder.wordpress.com/2013/01/10/updating-server-bookmarks-in-com-apple-sidebarlists-plis...).

obviously, you'll want to swap out for your server name, url and stdout path but here she is:

#!/bin/sh

# script to add a server to the list appearing at Go -> Connect to Server
# for all > 500 user accounts.
# to create your own shortcuts, just change the variables:
#
# ServerName = the name of the server you'd like to appear in your list
# ServerURL = the actual URL to that server
# LOG = whatever your sdout file is

# reference thanks to:
# Mike (http://jamfnation.jamfsoftware.com/viewProfile.html?userID=1927)
# Rich Trouton (http://derflounder.wordpress.com/2013/01/10/updating-server-bookmarks-in-com-apple-sidebarlists-plist/)

#----------------------------------------------------------
#   Variables
#----------------------------------------------------------

# --- assignments ---
ServerName="NAME OF YOUR SERVER" #doesn't need to be a URL
ServerURL="afp://PATH-TO-YOUR-SERVER-MOUNT"

# --- executables ---
Plist="/usr/libexec/PlistBuddy"

# --- directories ---
LOG="/PATH/TO/YOUR/LOGFILE.log"

# --- computationals ---
date=`date "+%A %m/%d/%Y %H:%M"`
over500=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`

# ---------------------------------------------------------------------------
#   Go to every user, back-up file, add new link, fix permissions
# ---------------------------------------------------------------------------
for i in $over500
do
    cd /Users/$i/Library/Preferences
    zip SidebarListsBackup.zip com.apple.sidebarlists.plist
    $Plist com.apple.sidebarlists.plist -c "Add :favoriteservers:CustomListItems:0 dict" >> $LOG
    $Plist com.apple.sidebarlists.plist -c "Add :favoriteservers:CustomListItems:0:Name string ${ServerName}" >> $LOG
    $Plist com.apple.sidebarlists.plist -c "Add :favoriteservers:CustomListItems:0:URL string ${ServerURL}" >> $LOG
    /usr/sbin/chown ${i}:staff /Users/$i/Library/Preferences/com.apple.sidebarlists.plist
done

exit 0

wmateo
Contributor

I was able to accomplish this packaging the plist using FEU/FUT and deploying it as a policy, and adding to self service After a restart, it worked fine. we didn't care what the user had in this list and we straight overwrote, and deploy with the once per computer trigger, allowing user to add. I know there is away using the defaults command, but could not get the syntax corrrect