Script Issue With Setting Finder Prefs

TomDay
Release Candidate Programs Tester

Sort of newbie here to scripting so looking for some help! I want to get the hard drive etc to show up on users desktops as they update to Yosemite or get a new computer with Yosemite. I'll include portion of the script below, I'm sure it's an easy fix, just need some knowledgeable eyes.

!/bin/bash

Initial setup script for Mac OS X 10.10.x

Last modified 05.27.2015

Show icons for hard drives, servers, and removable media on the desktop

/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

1 ACCEPTED SOLUTION

bpavlov
Honored Contributor

Need some context. How is this script being run? Is it through a Casper policy? Is it something installed through a package locally through a postinstall script or through a launch daemon or a launchagent?

Just so you're aware these are settings that can be set easily via a Configuration Profile through Casper this way its managed all the time.

Computers tab -> Configuration Profiles -> New -> Add the Finder payload and select the options you want.

View solution in original post

7 REPLIES 7

donmontalvo
Esteemed Contributor III

Might want to killall cfprefsd and killall Finder it too.

#!/bin/sh

/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;
/usr/bin/killall cfprefsd;
/usr/bin/killall Finder;

echo "OMG we killed Finder!"

exit 0
--
https://donmontalvo.com

bpavlov
Honored Contributor

Need some context. How is this script being run? Is it through a Casper policy? Is it something installed through a package locally through a postinstall script or through a launch daemon or a launchagent?

Just so you're aware these are settings that can be set easily via a Configuration Profile through Casper this way its managed all the time.

Computers tab -> Configuration Profiles -> New -> Add the Finder payload and select the options you want.

TomDay
Release Candidate Programs Tester

Thank you both, seems like the Config profile is the better option, feels like I'm making this harder than it needs to be with the script!

mm2270
Legendary Contributor III
these are settings that can be set easily via a Configuration Profile through Casper this way its managed all the time.

That little bit of info is important to keep in mind (emphasis added is mine). Unlike with older MCX, there isn't a way to set this once and then let the user decide on personal preference if they'd rather not see any HDs on the Desktop. Once set via Config Profile they cannot disable it. Just make sure you're OK with that.

TomDay
Release Candidate Programs Tester

@mm2270 Thanks for the additional note, will keep this in mind for sure. Just starting off with a very limited basic profile, like the way the Finder is set for these users now.

donmontalvo
Esteemed Contributor III

@TomDay Must be nice having APNS...<sniffle>...

:)

--
https://donmontalvo.com

matt4836
Contributor II

To answer your original question, ALL scripts run as root. When using the defaults command you need to specify the exact Preference Domain. If you abbreviate–

/usr/bin/defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true;

It will make the change to the user running the command. In this case Root. You could run it as a login policy (the easiest way to run as user) and do something like:

su "$3" -c  '/usr/bin/defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true'

Or modify the user template.