Skip to content

Instantly share code, notes, and snippets.

@AndrewWCarson
Last active August 23, 2018 04:46
Show Gist options
  • Save AndrewWCarson/6ad5574e52adcfb31aa729da4670f3d4 to your computer and use it in GitHub Desktop.
Save AndrewWCarson/6ad5574e52adcfb31aa729da4670f3d4 to your computer and use it in GitHub Desktop.
Add Favorite Servers in macOS
#!/bin/bash
# (C) Andrew Worth Carson
# MIT License: https://andrewworthcarson.com/mit_license.html
declare -a servers=('smb://server/share' 'smb://anotherserver/anothershare')
range=$(seq 0 1 $(expr ${#servers[@]} - 1))
for user in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
# Add each server to favorites
for index in $range; do
sudo -u "${user}" sfltool add-item -n "${servers[$index]}" com.apple.LSSharedFileList.FavoriteServers "${servers[$index]}"
done
done
@AndrewWCarson
Copy link
Author

Seems like sfltool add-item is deprecated. This no longer works in Mojave.

@AndrewWCarson
Copy link
Author

Improved user iteration significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment