-
Notifications
You must be signed in to change notification settings - Fork 6
/
setDock-resetDockToDefault.sh
48 lines (39 loc) · 1.2 KB
/
setDock-resetDockToDefault.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# version 1.0
# Written by: Mischa van der Bent
#
# Permission is granted to use this code in any way you want.
# Credit would be nice, but not obligatory.
# Provided "as is", without warranty of any kind, express or implied.
#
# DESCRIPTION
# This script resets the users docks back to factory defaults
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# Collect importend user information
# get the currently logged in user
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
# get uid logged in user
uid=$(id -u "${currentUser}")
# convenience function to run a command as the current user
# usage:
# runAsUser command arguments...
runAsUser() {
if [ "${currentUser}" != "loginwindow" ]; then
launchctl asuser "$uid" sudo -u "${currentUser}" "$@"
else
echo "no user logged in"
exit 1
fi
}
# reset Dock to default
runAsUser defaults delete com.apple.dock
echo "reset to default dock"
sleep 5
runAsUser killall cfprefsd
# Kill dock to reset it
killall Dock
exit 0