Hot Corner Script and Custom Dock Replacement with Default Dock

Mhomar
Contributor

Hi,

Using OS X 10.6.8, we are trying to programmatically change com.apple.dock settings to enforce some security guidelines at our company.
Everything is done through a perl script, and works absolutely flawlessly when I run it locally on the computer I want to change, logged on as myself.

Here is a basic snippet of what we've got:
-----------------------------
#!/usr/bin/perl

$user = "bob";
$file = "/Users/$user/Library/Preferences/com.apple.dock";

# Force Top-Right hot corner to "Start Screen Saver"
`defaults write $file wvous-tr-corner -integer 5`;
`defaults write $file wvous-tr-modifier -integer 0`;
`killall Dock`;
-----------------------------
However, when the change is executed from our JSS, it is doing something odd...The change is made to the dock plist file, however the Dock is reset to the system default settings. It looks like this only happens if the script actually makes a change. (i.e., if wvous-tr-corner was already set to 5, that would blow away the dock preferences) If we do not kill the Dock, the changes do not take effect, so we need a way to kill the Dock without it reverting back to the system default settings.

We can also duplicate this by issuing the "defaults write" and "killall" commands via Terminal. Note the "sudo"... When this script gets evoked from the JSS, it is called with a sudo, so we included it in our testing on the Terminal.

For example:
1.) Remove an icon or two from the Dock
2.) "sudo defaults write /Users/bob/Library/Preferences/com.apple.dock wvous-tr-corner -integer 5"
3.) "killall Dock"
4.) Once the Dock restarts, the icons removed in Step 1 reappear

Anybody know what is going on here? Is there any way to restart the Dock so that ~our~ changes take effect immediately, but the Dock doesn't revert back to the System default?

Thanks!

1 ACCEPTED SOLUTION

nessts
Valued Contributor II

my guess, you are running this script as root.
so when you run defaults write as root it changes the permissions and ownership and the user cannot read it, then when you killall Dock, Dock sees its fubar, and copies in the default file and owns it properly.
so either run this as a launchagent or chown and chmod the file at the end to the right perms.
chmod 0644 $file; chown $uid, $gid, $filename;
or system("chown $user $filename");

you should probably get used to encapsulating all your arguments in " too for all the wonderful things that have spaces in path names on mac.

View solution in original post

4 REPLIES 4

nessts
Valued Contributor II

my guess, you are running this script as root.
so when you run defaults write as root it changes the permissions and ownership and the user cannot read it, then when you killall Dock, Dock sees its fubar, and copies in the default file and owns it properly.
so either run this as a launchagent or chown and chmod the file at the end to the right perms.
chmod 0644 $file; chown $uid, $gid, $filename;
or system("chown $user $filename");

you should probably get used to encapsulating all your arguments in " too for all the wonderful things that have spaces in path names on mac.

Mhomar
Contributor

Wow! You all are GREAT to have on the JAMF Team! Special thanks to nessts for the prompt and accurate reply.

nessts
Valued Contributor II

its rare i find anybody who speaks perl so i really wanted to help you :)

waqas
New Contributor III

Thanks Guys.

Using the above input, I wrote the shell script to accomplish the same. The only difference is, I'm not using Killall Dock and the change happens after logout/login or reboot.

defaults write ~/Library/Preferences/com.apple.dock.plist wvous-tr-corner -integer 5
defaults write ~/Library/Preferences/com.apple.dock.plist wvous-tr-modifier -integer 0

chmod 600 ~/Library/Preferences/com.apple.dock.plist
chown $USER: ~/Library/Preferences/com.apple.dock.plist

VIVA JAMFNATION !!!!!!