-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_to_dock.sh
99 lines (89 loc) · 3.02 KB
/
add_to_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
function add_app_to_dock {
# adds an application to macOS Dock
# usage: add_app_to_dock "Application Name"
# example add_app_to_dock "Terminal"
app_name="${1}"
launchservices_path="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
app_path=$(${launchservices_path} -dump | grep -o "/.*${app_name}.app" | grep -v -E "Backups|Caches|TimeMachine|Temporary|/Volumes/${app_name}" | uniq | sort | head -n1)
if open -Ra "${app_path}"; then
echo "$app_path 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_path}</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
else
echo "ERROR: $1 not found."
fi
}
function add_folder_to_dock {
# adds a folder to macOS Dock
# usage: add_folder_to_dock "Folder Path" -s n -d n -v n
# example: add_folder_to_dock "~/Downloads" -d 0 -s 2 -v 1
# key:
# -s or --sortby
# 1 -> Name
# 2 -> Date Added
# 3 -> Date Modified
# 4 -> Date Created
# 5 -> Kind
# -d or --displayas
# 0 -> Stack
# 1 -> Folder
# -v or --viewcontentas
# 0 -> Automatic
# 1 -> Fan
# 2 -> Grid
# 3 -> List
folder_path="${1}"
sortby="1"
displayas="0"
viewcontentas="0"
while [[ "$#" -gt 0 ]]
do
case $1 in
-s|--sortby)
if [[ $2 =~ ^[1-5]$ ]]; then
sortby="${2}"
fi
;;
-d|--displayas)
if [[ $2 =~ ^[0-1]$ ]]; then
displayas="${2}"
fi
;;
-v|--viewcontentas)
if [[ $2 =~ ^[0-3]$ ]]; then
viewcontentas="${2}"
fi
;;
esac
shift
done
if [ -d "$folder_path" ]; then
echo "$folder_path added to the Dock."
defaults write com.apple.dock persistent-others -array-add "<dict>
<key>tile-data</key> <dict>
<key>arrangement</key> <integer>${sortby}</integer>
<key>displayas</key> <integer>${displayas}</integer>
<key>file-data</key> <dict>
<key>_CFURLString</key> <string>file://${folder_path}</string>
<key>_CFURLStringType</key> <integer>15</integer>
</dict>
<key>file-type</key> <integer>2</integer>
<key>showas</key> <integer>${viewcontentas}</integer>
</dict>
<key>tile-type</key> <string>directory-tile</string>
</dict>"
else
echo "ERROR: $folder_path not found."
fi
}
function add_spacer_to_dock {
# adds an empty space to macOS Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}'
}
function clear_dock {
# removes all persistent icons from macOS Dock
defaults write com.apple.dock persistent-apps -array
}
function reset_dock {
# reset macOS Dock to default settings
defaults write com.apple.dock; killall Dock
}