Script to edit Finder Favorites to Include AD Network Folder

GabeShack
Valued Contributor III

Hey all,
I'm trying to come up with a script that would add an AD users network shared folder to the favorites sidebar in finder. This would allow quick and easy saving from programs like Word as Students would not have to navigate through many subfolders to save a file.
Any thoughts?

Gabe Shackney
Instructional Technology Support
Princeton Public Schools

Gabe Shackney
Princeton Public Schools
18 REPLIES 18

jafuller
Contributor

You could run Composer to create a package. Then use native Finder to drag to the folder to the Favorites. Finish the package and see what it modifies. You may even be able to distribute this with FEU checked. Haven't tried it, but that's where I would start.

frozenarse
Contributor II

I originally went with the method that James described but it didn't seem to work very well for our Macbook users with mobile accounts. I can't completely remember the problems we had encountered but I just didn't apply that DMG to Macbooks. It DOES work for our regular workstation users so I can confirm that.

What I think is a better solution (for us at least) is to create a sidebar favorite that points to /Volumes instead of a specific mount. That way they can use that shortcut to quickly get into either their Home directory or any of their other mounted network shares.

GabeShack
Valued Contributor III

Well I could probably narrow that down by building and grade and just apply different composer solutions based on that. I was hoping there was a file I can edit and have this scripted to work on login.
Thanks for the ideas.

Gabe Shackney
Instructional Technology Support
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

frozenarse
Contributor II

com.apple.sidebarlists.plist is where you would need to tinker if you didn't already know.

GabeShack
Valued Contributor III

My problem is when saving with Word to a network share it wont let the user save correctly unless they have the direct path to the user folder. But if I drag the user folder to the side bar it saves fine.

Gabe Shackney
Princeton Public Schools

ACummins
New Contributor

Any update on this as I am currently having the same issue. Network drives are done via profile manager and added to the desktop. As above though they are not showing up in finder unless dragged or previously opened (so the recent is populated).

chrisx
New Contributor

Hi, i have a script for that, should I post it for u?

OneSeventeen
New Contributor II

I for one would love to see a script for that.
I can add all the shortcuts to my own sidebar and see them in the com.apple.sidebarlists.plist file, but I'd love to know how to add those keys to another mac using self service or automated policy without messing up their existing favorites.

mm2270
Legendary Contributor III

FWIW, if you are only dealing with 10.11 Macs and up, there is now a built in tool that can add in sidebar shortcuts. Prior to that, you needed to use some 3rd party custom tools or python scripts to do it. For example, here is one script that was posted on another thread: https://github.com/matt4836/changeSidebarLists/blob/master/Change_Sidebar_List.py

There is also a binary called mysides - https://github.com/mosen/mysides

On the mysides page the author notes the now built in way, which is pretty easy to use, called sfltool. Here's an example of how adding in an AD mounted share might be accomplished.

First the share would need to get mounted. The use that share path in the following command, but it has to be run as the user, so you'll need to use some tricks to get this to run against the logged in user from a Casper policy, or use something like a login policy trigger for example.

sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Volumes/ShareName

where /Volumes/ShareName is the location of the mounted sharepoint. I do think it needs to actually be mounted to add it this way. When I tried it without having the share mounted it created something with a blank icon and it wasn't working properly. When its does create it, the share name will show up in the Sidebar as an easy to access link from things like Open/Save dialogs. Even if the share gets dismounted, it can be mounted again by clicking on the icon in the sidebar, which remains there all the time.

Hope the above helps.

khey
Contributor

This is how we did it. Dock the shares which will work for mobile accounts as well provided that they have vpn access when off the network.

#!/bin/sh
Address=$4
Label=$5

/usr/bin/su -l $(logname) -c "/usr/local/bin/dockutil --add ${Address} --label '${Label}' --after Downloads"

killall Dock

exit

PatrickD
Contributor II

+1 for MySide Binary, works great and easy to use!

jartron3030
New Contributor III

I was successfully able to create Finder sidebar shortcuts to two network shares using both sfltool and mysides, as I wanted to try both, and sfltool works just fine on 10.11 and 10.12, but not 10.13... I read that Apple stripped out the ability to create Finder sidebar shortcuts using sfltool in 10.13, which I can confirm; thankfully mysides does still work in 10.13. I have the policy trigger set to login, and would ideally like for the policy to be set to ongoing or once per day so that in the scenario that a user accidentally deletes/removes the sidebar shortcut, it would be re-created at the next policy update...

However, this has an unintended consequence that I do not know how to fix or prevent; the policy creates a new set of shortcuts each time the user logs in. The only thing I can do to prevent this is to set the policy frequency to run once per user or once per user per computer. As I stated before, I would ideally like to have it get recreated if the user accidentally deletes it... I tried using

mysides remove $sharename

and

mysides remove $sharename file:///Volumes/$sharename

but neither of these work, and the policy log script result gives me a "Segmentation fault: 11 " on those lines of the script, and I don't know what that means... does anyone have any idea of how to remove network share shortcuts from the Finder sidebar using mysides, or is it not possible and I will just have to make sure to only run the policy once?

As an aside, and I am not sure that this matters, but the share paths are populated using JSS variables as I cannot hard code the paths into the script because certain shares are based on the AD user names and specific share paths that differ between users. I did try a version of my script with hard coded share paths just to see if it would work in that case, but it still failed with "Segmentation fault: 11"...

mm2270
Legendary Contributor III

@jartron3030 Couple of things. First, I highly recommend using full paths to the mysides tool in a policy, as simply using mysides may not resolve properly to the actual binary. That may not be the issue here, but best practice for 3rd party tools, especially when they get run via a policy, is to include the proper full path and not risk it.

Second, why not use a full script to use mysides to list the contents of the Finder sidebar first, check to see if the share in question is in the list, and if not, then add it in, instead of just adding it in blindly on each run? That would avoid adding duplicates and needing to delete items, then re-add them. In other words, put some logic into that it only takes action to add it if it's missing.

jartron3030
New Contributor III

@mm2270 thank you for your response! I am using full paths in my script, and I totally agree with you about 3rd party tools.

Your suggestion to use mysides to list the Finder sidebar first is very interesting and I would love to try that, and please forgive my ignorance on this, but I am not entirely sure how I would write the logic within the context of the mysides commands to check the list and only add the shares if they are not already part of the list.

When I use

mysides list

in Terminal to list the Finder sidebar contents, it shows the actual share names that were populated from the JSS variables I put into the policy (script I am using is below). Do you think that your suggestion would work when using variables?

I would love to test if you or someone might be able to help me with how to write that part of the script...

here's the script currently, it is an comprised of some other scripts I've used and found here:

#!/bin/sh

username="$3"
    if [ -z "$username" ]; then
        username="$USER"
    fi
    echo "User: $username"
shareName="$4"
    echo "Sharename: $4"

/usr/local/bin/mysides add $username file:///Volumes/$username
/usr/local/bin/mysides add $shareName file:///Volumes/$shareName

exit 0

Thank you!

mm2270
Legendary Contributor III

@jartron3030 You can try the following modification:

#!/bin/sh

username="$3"
if [ -z "$username" ]; then
    username="$USER"
fi

echo "User: $username"
shareName="$4"
echo "Sharename: $4"

userShareCheck=$(/usr/local/bin/mysides list | grep "file:///Volumes/$username")
shareCheck=$(/usr/local/bin/mysides list | grep "file:///Volumes/$shareName")

if [ -z "$userShareCheck" ]; then
    /usr/local/bin/mysides add $username file:///Volumes/$username
else
    echo "Sidebar item $username already exists"
fi

if [ -z "$shareCheck" ]; then
    /usr/local/bin/mysides add $shareName file:///Volumes/$shareName
else
    echo "Sidebar item $shareName already exists"
fi

exit 0

jartron3030
New Contributor III

@mm2270 That worked like a charm! I am still learning bash and after seeing how you wrote this, it makes so much sense... This will surely be useful for me in the future when I am needing to do something like this again. Thank you so much!

Edit: Unfortunately I must amend my last messaged.... it works like a charm for Sierra, but strangely it doesn't work in High Sierra... it creates the shortcuts, but they don't seem to link to the shares... When I click on the shortcut it pops up with an error that says "[username] can't be opened because the original item can't be found". It's weird because I have a policy in effect to mount the shares at login as well, and it is indeed doing so so the paths should be correct; before it would create a workable shortcut, it would just add it over and over unless I set the policy trigger frequency to once per computer. Sigh.. High Sierra seems to be problematic...

jartron3030
New Contributor III

@mm2270 I got it working this morning and wanted to update you! I just added each share check and if/then/else statements to the end of each of the mount scripts instead of in its own script, this way the drives mount first and then mysides checks to see if they are already in the sidebar list and if so they skip them and if not they add them... thank you so much for your help!

mm2270
Legendary Contributor III

@jartron3030 Glad you got it working! I guess it makes sense that if the actual shares aren't fully mounted yet when mysides kicks in to add those, that it will add a broken sidebar item.