-
Notifications
You must be signed in to change notification settings - Fork 0
/
dock.sh
174 lines (149 loc) · 4.36 KB
/
dock.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
# https://github.com/rpavlick/add_to_dock
# adds an application to macOS Dock
# usage: add_app_to_dock "Application Name"
# example add_app_to_dock "/System/Applications/Music.app"
function add_app_to_dock {
app="${1}"
if open -Ra "${app}"; then
echo "$app added to the Dock."
defaults write com.apple.dock static-apps -array-add "<dict>
<key>tile-data</key>
<dict>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>${app}</string>
<key>_CFURLStringType</key>
<integer>0</integer>
</dict>
</dict>
</dict>"
else
echo "ERROR: Application $1 not found."
fi
}
# adds a folder to macOS Dock
# usage: add_folder_to_dock "Folder Path" -a n -d n -v n
# example: add_folder_to_dock "~/Downloads" -a 2 -d 0 -v 1
# key:
# -a or --arrangement
# 1 -> Name
# 2 -> Date Added
# 3 -> Date Modified
# 4 -> Date Created
# 5 -> Kind
# -d or --displayAs
# 0 -> Stack
# 1 -> Folder
# -v or --showAs
# 0 -> Automatic
# 1 -> Fan
# 2 -> Grid
# 3 -> List
function add_folder_to_dock {
folder="${1}"
arrangement="1"
displayAs="0"
showAs="0"
while [[ "$#" -gt 0 ]]; do
case $1 in
-a|--arrangement)
if [[ $2 =~ ^[1-5]$ ]]; then
arrangement="${2}"
fi
;;
-d|--displayAs)
if [[ $2 =~ ^[0-1]$ ]]; then
displayAs="${2}"
fi
;;
-v|--showAs)
if [[ $2 =~ ^[0-3]$ ]]; then
showAs="${2}"
fi
;;
esac
shift
done
if [ -d "$folder" ]; then
echo "$folder added to the Dock."
defaults write com.apple.dock persistent-others -array-add "<dict>
<key>tile-data</key>
<dict>
<key>arrangement</key>
<integer>${arrangement}</integer>
<key>displayas</key>
<integer>${displayAs}</integer>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>file://${folder}</string>
<key>_CFURLStringType</key>
<integer>15</integer>
</dict>
<key>file-type</key>
<integer>2</integer>
<key>showas</key>
<integer>${showAs}</integer>
</dict>
<key>tile-type</key>
<string>directory-tile</string>
</dict>"
else
echo "ERROR: Folder $folder not found."
fi
}
function add_spacer_to_dock {
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'
}
function add_small_spacer_to_dock {
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}'
}
function clear_apps_from_dock {
defaults delete com.apple.dock persistent-apps
}
function clear_static_apps_from_dock {
defaults delete com.apple.dock static-apps
}
function clear_others_from_dock {
defaults delete com.apple.dock persistent-others
}
function clear_dock {
clear_static_apps_from_dock
clear_apps_from_dock
clear_others_from_dock
}
function disable_recent_apps_from_dock {
defaults write com.apple.dock show-recents -bool false
}
function enable_recent_apps_from_dock {
defaults write com.apple.dock show-recents -bool true
}
function reset_dock {
defaults delete com.apple.dock
killall Dock
}
# '/System/Applications/Utilities/Terminal.app'
# '/Applications/Slack.app'
# '/Applications/Google Chrome.app'
# '/Applications/VLC.app'
# '/System/Applications/System Settings.app'
declare -a apps=(
'/System/Applications/Launchpad.app'
'/Applications/Google Chrome.app'
'/Applications/Slack.app'
'/System/Applications/System Settings.app'
);
declare -a folders=(
~/Downloads
);
clear_dock
disable_recent_apps_from_dock
for app in "${apps[@]}"; do
add_app_to_dock "$app"
done
for folder in "${folders[@]}"; do
add_folder_to_dock $folder
done
killall Dock