-
Notifications
You must be signed in to change notification settings - Fork 3
/
prepDockLauncher.sh
87 lines (71 loc) · 2.61 KB
/
prepDockLauncher.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Define LaunchDaemon variables
launchdaemon_identifier="com.contoso.docksettings"
launchdaemon_filepath="/Library/LaunchDaemons/${launchdaemon_identifier}.plist"
launchdaemon_program_filepath="/tmp/setDock.sh"
launchdaemon_watchpath="/Applications/zoom.us.app"
# Create LaunchDaemon that launches script after last Auto App is installed
cat <<EOF > "${launchdaemon_filepath}"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${launchdaemon_identifier}</string>
<key>Program</key>
<string>${launchdaemon_program_filepath}</string>
<key>RunAtLoad</key>
<false/>
<key>WatchPaths</key>
<array>
<string>${launchdaemon_watchpath}</string>
</array>
</dict>
</plist>
EOF
# Create program script
cat <<EOF > "${launchdaemon_program_filepath}"
#!/bin/zsh --no-rcs
autoload is-at-least
installedOSversion=\$(sw_vers -productVersion)
launchdaemon_filepath="/Library/LaunchDaemons/com.contoso.docksettings.plist"
currentUser=\$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print \$3 }' )
uid=\$(id -u "\$currentUser")
echo "\$currentUser and \$uid"
if is-at-least 13 "\$installedOSversion"; then
settingsPath=/System/Applications/System\ Settings.app
else
settingsPath=/System/Applications/System\ Preferences.app
fi
runAsUser() {
if [ "\$currentUser" != "loginwindow" ]; then
launchctl asuser "\$uid" sudo -u "\$currentUser" "\$@"
else
echo "no user logged in"
fi
}
dock_item() {
printf '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>%s</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>', "\$1"
}
sleep 5
runAsUser defaults write com.apple.terminal SecureKeyboardEntry -bool "true"
runAsUser defaults delete com.apple.dock persistent-apps
runAsUser defaults write com.apple.dock "show-recents" -bool "false"
runAsUser defaults write com.apple.dock persistent-apps -array \
"\$(dock_item /System/Applications/Launchpad.app)" \
"\$(dock_item /Applications/Google\ Chrome.app)" \
"\$(dock_item /Applications/Slack.app)" \
"\$(dock_item /Applications/zoom.us.app)" \
"\$(dock_item /Applications/Self Service.app)" \
"\$(dock_item "\$settingsPath")"
killall Dock
launchctl unload "\${launchdaemon_filepath}"
rm "\${launchdaemon_filepath}"
rm "/tmp/setDock.sh"
exit 0
EOF
chmod a+x "${launchdaemon_program_filepath}"
# Load LaunchDaemon
launchctl load "${launchdaemon_filepath}"
# Exit
exit 0