The slftool thread

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.

# 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 ]
su - "$loggedInUser" -c "/usr/local/bin/mysides remove All My Files file:///System/Library/CoreServices/" && 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 file:///Users/$loggedInUser && sleep 2
/usr/bin/sfltool add-item file:///Users/$loggedInUser/Desktop && sleep 2
/usr/bin/sfltool add-item file:///Users/$loggedInUser/Documents && sleep 2
/usr/bin/sfltool add-item file:///Users/$loggedInUser/Downloads && sleep 2
/usr/bin/sfltool add-item file:///Users/$loggedInUser/Movies && sleep 2
/usr/bin/sfltool add-item file:///Users/$loggedInUser/Music && sleep 2
/usr/bin/sfltool add-item file:///Users/$loggedInUser/Pictures && sleep 2
touch /Users/$loggedInUser/.sidebarshortcuts
/usr/libexec/PlistBuddy -c "Add bool False" /Users/$loggedInUser/Library/Preferences/
/usr/libexec/PlistBuddy -c "Add bool False" /Users/$loggedInUser/Library/Preferences/
killall cfprefsd

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 "./", 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...

Noah Blair

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.



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)

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 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.

Valued Contributor II

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

  File "", line 123, in <module>

    item["Name"] = unicode(server)

NameError: name 'unicode' is not defined

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.

Valued Contributor II

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.

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.

Valued Contributor

Has anyone gotten this to work with Python3?