-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdock_operations.sh
More file actions
140 lines (123 loc) · 3.72 KB
/
dock_operations.sh
File metadata and controls
140 lines (123 loc) · 3.72 KB
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
#!/usr/bin/env bash
# https://github.com/rpavlick/add_to_dock
# https://gist.github.com/kamui545/c810eccf6281b33a53e094484247f5e8
# 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 persistent-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_others_from_dock {
defaults delete com.apple.dock persistent-others
}
function clear_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
}