Posted on 04-12-2018 04:57 PM
Hello,
I have a script that edits the Finder plist (com.apple.finder.plist) and changes it to fit our needs. It runs perfectly well when it is a .command and executed by double clicking on it, but it does not fully execute when put inside a package or when set as a login policy (in either .pkg, .command, or .sh formats). It also doesn't execute correctly when put on the desktop or other location and called via "sudo sh /path-to-file" in Terminal.
The only part that works when triggered via JAMF or a .pkg is the part where it adds items to the Favorites sidebar in Finder. The rest of it does not work.
Our intent is to have this run once per user at logon, which will set up a default Finder experience, but allow the user to change it as they see fit, so Configuration Profiles which will make the changes static don't fit our needs.
Any help would be appreciated.
#!/bin/bash
#Add Movies, Music, Pictures, <username>, to Finder Favorites sidebar.
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
if [ -e /usr/bin/sfltool ]
then
/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
/usr/bin/sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$loggedInUser && sleep 2
touch /Users/$loggedInUser/.sidebarshortcuts
fi
#Turns on show Hard Disks, External disks, CDs, DVDs, and iPads, and Connected Servers
/usr/bin/defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true;
/usr/bin/defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true;
/usr/bin/defaults write com.apple.finder ShowMountedServersOnDesktop -bool true;
/usr/bin/defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true;
#Shows Status Bar
/usr/bin/defaults write com.apple.finder ShowStatusBar -bool true;
#Shows Tab View
/usr/bin/defaults write com.apple.finder ShowTabView -bool true;
#Shows Path Bar
/usr/bin/defaults write com.apple.finder ShowPathbar -bool true;
#Changes Finder to List View
#Four-letter codes for the other view modes: 'icnv', 'clmv', 'Flwv'
/usr/bin/defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
#New Finder windows now opens in /Users/<username>
/usr/bin/defaults write com.apple.finder NewWindowTarget -string "PfHm"
#Restarts cfprefsd and Finder
killAll cfprefsd
killAll Finder
echo "Finder Preferences set"
exit 0
Posted on 04-13-2018 12:11 AM
Can you please post the script again by using the >_ icon right above this text box here. It got mangled in your post and it's not readable.
Posted on 04-13-2018 12:23 AM
Jamf Nation users should be warned before posting anything with "#!"
Posted on 04-13-2018 09:46 AM
Sorry, new to this website. I've updated the original post @gda
Posted on 04-15-2018 02:06 PM
Most of those defaults commands are user specific, this means that when you wrap them in a pkg or run them as a script from JAMF they are being run as the system and writing to the machine settings not the logged in user. You probably need to get each command run as the currently logged in user or you need to specify the exact plist file within the users settings to store the settings.
Posted on 04-27-2018 03:31 PM
Here is the updated script in case anyone wants to know how to get JAMF to change the user experience:
#!/bin/bash
#Finds current username and defines a variable
currentuser=`stat -f "%Su" /dev/console`
#Substituting as user stored in variable to modify plist
#su "$currentuser" -c "<command to run>"
#Add Movies, Music, Pictures, <username>, to Finder Favorites sidebar.
su "$currentuser" -c "sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$currentuser && sleep 2"
su "$currentuser" -c "sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$currentuser/Movies && sleep 2"
su "$currentuser" -c "sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$currentuser/Music && sleep 2"
su "$currentuser" -c "sfltool add-item com.apple.LSSharedFileList.FavoriteItems file:///Users/$currentuser/Pictures && sleep 2"
su "$currentuser" -c "touch /Users/$currentuser/.sidebarshortcuts"
#Turns on show Hard Disks, External disks, CDs, DVDs, and iPads, and Connected Servers
su "$currentuser" -c "defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowMountedServersOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true;"
#Shows Status Bar
su "$currentuser" -c "defaults write com.apple.finder ShowStatusBar -bool true;"
#Shows Tab View
su "$currentuser" -c "defaults write com.apple.finder ShowTabView -bool true;"
#Shows Path Bar
su "$currentuser" -c "defaults write com.apple.finder ShowPathbar -bool true;"
#Changes Finder to List View
#Four-letter codes for the other view modes: 'icnv', 'clmv', 'Flwv'
su "$currentuser" -c "defaults write com.apple.finder FXPreferredViewStyle -string 'Nlsv'"
#New Finder windows now opens in /Users/<username>
su "$currentuser" -c "defaults write com.apple.finder NewWindowTarget -string 'PfHm'"
#Turns off re-open programs/windows after restart/login/shutdown
su "$currentuser" -c "defaults write com.apple.loginwindow.plist TALLogoutSavesState -bool false"
#Restarts cfprefsd and Finder
killAll cfprefsd
killAll Finder
echo "Finder Preferences set"
exit 0
Posted on 04-16-2019 10:30 AM
sfltool has been killed by Apple does anyone else know another way to handle this?
Posted on 05-03-2020 07:25 AM
@donjakubczak I'm using mysides