-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockutil
More file actions
105 lines (90 loc) · 3.42 KB
/
Copy pathdockutil
File metadata and controls
105 lines (90 loc) · 3.42 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
#!/usr/bin/python
# python wrapper for dockutil. We use the --no-restart flag for most of this
# to reduce the amount of flashes (to one) that occur on the user's desktop.
# Written by Erik Gomez
# Edited by Andrew Doering - 2019/05/16
# Updated on 2019/09/20 - Add Mojave and Catalina support check - basically an if statement
# Edited check - Thijs v Vught
# Update on 2020/07/16 - BigSur compatible
import os
import subprocess
import platform
def dockutil(type, itempath, norestart):
if norestart is True:
cmd = ['/usr/local/bin/dockutil', type, itempath, '--no-restart']
else:
cmd = ['/usr/local/bin/dockutil', type, itempath]
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, err = proc.communicate()
return output
except Exception:
return None
def dockutilFolder(type, itempath, norestart, sorttype):
if norestart is True:
cmd = ['/usr/local/bin/dockutil', type, itempath, '--sort', sorttype,
'--no-restart']
else:
cmd = ['/usr/local/bin/dockutil', type, itempath, '--sort', sorttype]
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, err = proc.communicate()
return output
except Exception:
return None
def main():
# Remove all dock items.
dockutil('--remove', 'all', True)
# Add the paths of the items you want to add to the dock here.
applistCatalina = [
'/System/Applications/Launchpad.app',
'/Applications/Safari.app',
'/Applications/Microsoft Edge.app',
'/Applications/VLC.app',
'/System/Applications/Notes.app',
'/System/Applications/Contacts.app',
'/System/Applications/Calendar.app',
'/System/Applications/App Store.app',
'/Applications/Microsoft Word.app',
'/Applications/Microsoft PowerPoint.app',
'/Applications/Microsoft Outlook.app',
'/Applications/Microsoft Excel.app',
'/Applications/Microsoft Teams.app',
'/System/Applications/Preview.app',
'/System/Applications/System Preferences.app',
'/Applications/Self Service.app',
]
applistMojave = [
'/Applications/Launchpad.app',
'/Applications/Safari.app',
'/Applications/Microsoft Edge.app',
'/Applications/VLC.app',
'/Applications/Notes.app',
'/Applications/Contacts.app',
'/Applications/Calendar.app',
'/Applications/App Store.app',
'/Applications/Microsoft Outlook.app',
'/Applications/Microsoft Word.app',
'/Applications/Microsoft PowerPoint.app',
'/Applications/Microsoft Excel.app',
'/Applications/Microsoft Teams.app',
'/Applications/Preview.app',
'/Applications/System Preferences.app',
'/Applications/Self Service.app',
]
v = platform.mac_ver()[0]
v = float('.'.join(v.split('.')[:2]))
if v >= 10.15:
for itempath in applistCatalina:
if os.path.isdir(itempath):
dockutil('--add', itempath, True)
else:
for itempath in applistMojave:
if os.path.isdir(itempath):
dockutil('--add', itempath, True)
# Tell dockutil to restart and finally update the dock.
dockutilFolder('--add', '~/Downloads', False, 'name')
if __name__ == '__main__':
main()