Finder Settings Script

jwm3wn
New Contributor III

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

gda
Contributor

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.

donmontalvo
Esteemed Contributor III

jwm3wn
New Contributor III

Sorry, new to this website. I've updated the original post @gda

Look
Valued Contributor III

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.

jwm3wn
New Contributor III

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

donjakubczak
New Contributor III

sfltool has been killed by Apple does anyone else know another way to handle this?

julienvs
New Contributor III