The slftool thread

djdavetrouble
Contributor III

So, el capitan has a new binary called sfltool. It has been discussed a few times, and I have incorporated it into my firstrun script to add items to the sidebar. I think many more uses for this will be discovered.
Here is my script as an example.

#!/bin/bash
# Get the Username of the currently logged user
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
if [ -e /usr/local/bin/mysides ]
then
su - "$loggedInUser" -c "/usr/local/bin/mysides remove All My Files file:///System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries/myDocuments.cannedSearch/" && sleep 2
su - "$loggedInUser" -c "/usr/local/bin/mysides remove iCloud x-apple-finder:icloud" && sleep 2
su - "$loggedInUser" -c "/usr/local/bin/mysides remove domain-AirDrop nwnode://domain-AirDrop" && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser/Desktop && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser/Documents && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser/Downloads && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser/Movies && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser/Music && sleep 2
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser/Pictures && sleep 2
touch /Users/$loggedInUser/.sidebarshortcuts
fi
/usr/libexec/PlistBuddy -c "Add :networkbrowser:CustomListProperties:com.apple.NetworkBrowser.backToMyMacEnabled bool False" /Users/$loggedInUser/Library/Preferences/com.apple.sidebarlists.plist
/usr/libexec/PlistBuddy -c "Add :networkbrowser:CustomListProperties:com.apple.NetworkBrowser.bonjourEnabled bool False" /Users/$loggedInUser/Library/Preferences/com.apple.sidebarlists.plist
killall cfprefsd
49 REPLIES 49

noahinla
New Contributor II

Hi @korylprince

I tried running the most recent version of your script from your GitHub page, but I'm getting the error:

" File "./connecttoserver_v2.py", line 20 "Get users with a home directory in /Users" ^
IndentationError: expected an indented block"

Am I doing something wrong?

Edit: Nevermind, I just don't know how to use GitHub properly...
Thanks,

Noah Blair

tuck_itadmin
New Contributor

@korylprince this was working great up until Catalina. But I guess some Python functionality has been deprecated, including the Foundation module. Do you happen to have a workaround for this? And thank you for creating this script to begin with, it's been a total lifesaver for me.

Thanks,

Chris

apizz
Valued Contributor

If the sidebar is all you care about @tuck.itadmin have you tried mysides? We're not on Catalina but still works great on Mojave (10.14.6)

korylprince
New Contributor II

I'm just now getting to testing this with Catalina. Catalina didn't remove python, just deprecated it; so we're fine for now. When it's gone we'll have to come up with another alternative (maybe a compiled Swift app?)

My scripts work, however there are some caveats. If you try to run the script directly in terminal, you'll find it runs, but it doesn't work. It turns out the com.apple.sharedfilelist directory is now protected along with the other security improvements in Catalina. To get it to run, you have to enable full disk access for terminal in the Security & Privacy settings.

I have not yet attempted to run the script in an automated process, so I'm not sure what, if any, hoops you'll have to jump through to get it to run properly.

dstranathan
Valued Contributor II

By chance has anyone updated this handy script for Python3? I am seeing an error:

  File "configureServerFavorites.py", line 123, in <module>

    item["Name"] = unicode(server)

NameError: name 'unicode' is not defined

dstranathan
Valued Contributor II

Figured it out: Python3 doesn't need Unicode to be explicitly defined as Python2 did - it supports Unicode by default. So I changed type 'unicode' to type 'str' and resolved the issue.

obi-k
Valued Contributor III

Hi @korylprince

Any chance you have an update on this awesome script? Looks like 12.3 and up said bye to Python 2. Here's the error now:

 
/usr/bin/python: bad interpreter: No such file or directory
Error running script: return code was 126.

12.3 said goodbye to all versions of python. Going forward you'll need to install it yourself if you want to use python.

korylprince
New Contributor II

I've updated the scripts and tested them on successfully on 12.3.1 with Munki's python. Make sure to read the comments there. I'm also working on a compiled solution to this so python won't be required, but have no ETA on when that will be ready.

cwaldrip
Valued Contributor

Has anyone gotten this to work with Python3?