27
27
# # Lines 146 onwards confiure Dock look and feel, uncomment as necessary
28
28
# #
29
29
30
- # Define variables
31
- log=" $HOME /addAppstoDock.log"
30
+ # Dock Configuration Values
31
+ autoHideDock=false
32
+ magnification=false
33
+ dimHiddenApps=true
34
+ showRecentItems=true
35
+ enableMinimiseIconsToDock=true
36
+
37
+ # Script Configuration
38
+ secondsToWaitForOtherApps=3600
32
39
appname=" Dock"
33
- startCompanyPortalifADE=" true"
34
- consoleuser=$( ls -l /dev/console | awk ' { print $3 }' )
35
- secondsToWaitForOtherApps=3600 # How long should we wait for other apps to install before we continue?
36
-
37
40
41
+ # Define log and start logging...
42
+ log=" /var/tmp/addAppstoDock.log"
38
43
exec & > >( tee -a " $log " )
39
44
40
- if [[ -f " $HOME /Library/Logs/prepareDock" ]]; then
45
+ # Lets find out who we're running as...
46
+ scriptRunningAs=$( whoami)
47
+ desktopUser=$( who | awk ' /console/{print $1}' )
48
+
49
+ # Determine home directory
50
+ desktopUserHomeDirectory=$( dscl . -read " /users/$desktopUser " NFSHomeDirectory | cut -d " " -f 2)
51
+ plist=" ${desktopUserHomeDirectory} /Library/Preferences/com.apple.dock.plist"
52
+
53
+ echo " The script is running under the user: $scriptRunningAs "
54
+ echo " The current desktop user is: $desktopUser "
55
+ echo " The current desktop users home directory is: $desktopUserHomeDirectory "
56
+
57
+ # Check if an script has already run before
58
+ if [[ -f " $desktopUserHomeDirectory /Library/Logs/prepareDock" ]]; then
41
59
42
60
echo " $( date) | Script has already run, nothing to do"
43
61
exit 0
44
62
45
63
fi
46
64
65
+ # Wait for Dock...
66
+ until ps aux | grep /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock | grep -v grep & > /dev/null; do
67
+ delay=$(( $RANDOM % 50 + 10 ))
68
+ echo " $( date) | + Dock not running, waiting [$delay ] seconds"
69
+ sleep $delay
70
+ done
71
+ echo " $( date) | Dock is here, lets carry on"
72
+
47
73
# workaround for Ventura (macOS Ver 13.x) System Settings.app name change
48
74
if [[ -a " /System/Applications/System Settings.app" ]]; then settingsApp=" System Settings.app" ; else settingsApp=" System Preferences.app" ; fi
49
75
@@ -54,20 +80,14 @@ dockapps=( "/System/Applications/Launchpad.app"
54
80
" /Applications/Microsoft Excel.app"
55
81
" /Applications/Microsoft PowerPoint.app"
56
82
" /Applications/Microsoft OneNote.app"
57
- " /Applications/Microsoft Teams Classic .app"
83
+ " /Applications/Microsoft Teams.app"
58
84
" /Applications/Visual Studio Code.app"
59
85
" /Applications/Company Portal.app"
60
86
" /Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app"
61
87
" /System/Applications/App Store.app"
62
88
" /System/Applications/Utilities/Terminal.app"
63
89
" /System/Applications/$settingsApp " )
64
90
65
- # Uncomment these lines if you want to add network shares to the Dock
66
-
67
- # netshares=( "smb://192.168.0.12/Data"
68
- # "smb://192.168.0.12/Home"
69
- # "smb://192.168.0.12/Tools")
70
-
71
91
echo " "
72
92
echo " ##############################################################"
73
93
echo " # $( date) | Starting install of $appname "
@@ -90,7 +110,7 @@ function updateSplashScreen () {
90
110
if [[ -a " /Library/Application Support/Dialog/Dialog.app/Contents/MacOS/Dialog" ]]; then
91
111
92
112
93
- echo " $( date) | Updating Swift Dialog monitor for [$appname ] to [$1 ]"
113
+ echo " $( date) | Updating Swift Dialog monitor for [$appname ] to [$1 ]"
94
114
echo listitem: title: $appname , status: $1 , statustext: $2 >> /var/tmp/dialog.log
95
115
96
116
# Supported status: wait, success, fail, error, pending or progress:xx
@@ -99,32 +119,6 @@ function updateSplashScreen () {
99
119
100
120
}
101
121
102
- # function to delay until the user has finished setup assistant.
103
- waitForDesktop () {
104
- until ps aux | grep /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock | grep -v grep & > /dev/null; do
105
- delay=$(( $RANDOM % 50 + 10 ))
106
- echo " $( date) | + Dock not running, waiting [$delay ] seconds"
107
- sleep $delay
108
- done
109
- echo " $( date) | Dock is here, lets carry on"
110
- }
111
-
112
- # Workaround to be used during phasing in the new Microsoft Teams
113
- function checkAndSetInstalledMSTeamsPath () {
114
- if [[ $( echo " $1 " | grep -c " Microsoft Teams" ) -gt 0 ]]; then
115
- if [[ -a " /Applications/Microsoft Teams.app" ]]; then
116
- i=" /Applications/Microsoft Teams.app"
117
- elif [[ -a " /Applications/Microsoft Teams classic.app" ]]; then
118
- i=" /Applications/Microsoft Teams classic.app"
119
- elif [[ -a " /Applications/Microsoft Teams (work or school).app" ]]; then
120
- i=" /Applications/Microsoft Teams (work or school).app"
121
- elif [[ -a " /Applications/Microsoft Teams (work preview).app" ]]; then
122
- i=" /Applications/Microsoft Teams (work preview).app"
123
- fi
124
- fi
125
- }
126
-
127
- waitForDesktop
128
122
129
123
START=$( date +%s) # define loop start time so we can timeout gracefully
130
124
echo " $( date) | Looking for required applications..."
@@ -140,7 +134,6 @@ while [[ $ready -ne 1 ]];do
140
134
missingappcount=0
141
135
142
136
for i in " ${dockapps[@]} " ; do
143
- checkAndSetInstalledMSTeamsPath " $i "
144
137
if [[ -a " $i " ]]; then
145
138
echo " $( date) | $i is installed"
146
139
else
@@ -162,70 +155,77 @@ while [[ $ready -ne 1 ]];do
162
155
163
156
done
164
157
158
+
159
+ # Check if /usr/local/bin/dockutil is present, if not quit
160
+ if [[ ! -a " /usr/local/bin/dockutil" ]]; then
161
+ echo " $( date) | dockutil is not present, exiting"
162
+ updateSplashScreen fail " Dockutil is missing"
163
+ exit 1
164
+ fi
165
+
165
166
updateSplashScreen wait " Installing"
166
167
167
- echo " $( date) | Removing Dock Persistent Apps"
168
- defaults delete $HOME /Library/Preferences/com.apple.dock persistent-apps
169
- defaults delete $HOME /Library/Preferences/com.apple.dock persistent-others
170
168
169
+ # Clear the dock
170
+ echo " $( date) | Clearing Dock Items"
171
+ sudo -i -u $desktopUser /usr/local/bin/dockutil --remove all --no-restart > /dev/null 2>&1
172
+
173
+ # Add the apps to the dock
171
174
echo " $( date) | Adding Apps to Dock"
172
175
for i in " ${dockapps[@]} " ; do
173
- checkAndSetInstalledMSTeamsPath " $i "
174
176
if [[ -a " $i " ]] ; then
175
- echo " $( date) | Adding [$i ] to Dock"
176
- defaults write com.apple.dock persistent-apps -array-add " <dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$i </string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
177
+ echo " $( date) | + Adding [$i ] to Dock"
177
178
updateSplashScreen wait " Adding $i to Dock"
179
+ sudo -i -u $desktopUser /usr/local/bin/dockutil --add " $i " --no-restart > /dev/null 2>&1
178
180
fi
179
181
done
180
182
181
- if [[ " $netshares " ]]; then
182
- echo " $( date) | Adding Network Shares to Dock"
183
- for j in " ${netshares[@]} " ; do
184
- label=" $( basename $j ) "
185
- echo " $( date) | Adding [$j ][$label ] to Dock"
186
- defaults write com.apple.dock persistent-others -array-add " <dict><key>tile-data</key><dict><key>label</key><string>$label </string><key>url</key><dict><key>_CFURLString</key><string>$j </string><key>_CFURLStringType</key><integer>15</integer></dict></dict><key>tile-type</key><string>url-tile</string></dict>"
187
- updateSplashScreen wait " Adding $j to Dock"
188
- done
189
- fi
190
-
183
+ # Add the Download folder to the dock
191
184
echo " $( date) | Adding Downloads Stack"
192
- consoleuser=$( ls -l /dev/console | awk ' { print $3 }' )
193
- downloadfolder=" $HOME /Downloads"
194
- defaults write com.apple.dock persistent-others -array-add " <dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$downloadfolder </string><key>_CFURLStringType</key><integer>0</integer></dict><key>file-label</key><string>Downloads</string><key>file-type</key><string>2</string></dict><key>tile-type</key><string>directory-tile</string></dict>"
195
-
196
-
197
- echo " $( date) | Enabling Magnification"
198
- defaults write com.apple.dock magnification -boolean YES
199
-
200
- echo " $( date) | Enable Dim Hidden Apps in Dock"
201
- defaults write com.apple.dock showhidden -bool true
202
-
203
- # echo "$(date) | Enable Auto Hide dock"
204
- # defaults write com.apple.dock autohide -bool true
205
-
206
- echo " $( date) | Disable show recent items"
207
- defaults write com.apple.dock show-recents -bool FALSE
208
-
209
- echo " $( date) | Enable Minimise Icons into Dock Icons"
210
- defaults write com.apple.dock minimize-to-application -bool yes
211
-
185
+ downloadfolder=" $desktopUserHomeDirectory /Downloads"
186
+ updateSplashScreen wait " Adding $downloadfolder to Dock"
187
+ sudo -i -u $desktopUser /usr/local/bin/dockutil --add " $downloadfolder " --view fan --display stack --sort dateadded --no-restart > /dev/null 2>&1
188
+
189
+ # Add the Documents folder to the dock
190
+ echo " $( date) | Adding Documents Stack"
191
+ documentsFolder=" $desktopUserHomeDirectory /Documents"
192
+ updateSplashScreen wait " Adding $documentsFolder to Dock"
193
+ sudo -i -u $desktopUser /usr/local/bin/dockutil --add " $documentsFolder " --view fan --display stack --sort dateadded --no-restart > /dev/null 2>&1
194
+
195
+ # Configure Settings Magnification
196
+ echo " $( date) | Setting Magnification to ${magnification} "
197
+ updateSplashScreen wait " Setting Magnification to ${magnification} "
198
+ sudo -i -u $desktopUser defaults write " ${desktopUserHomeDirectory} /Library/Preferences/com.apple.dock.plist" magnification -boolean ${magnification}
199
+
200
+ # Configure Dim Hidden Apps
201
+ echo " $( date) | Setting Dim Hidden Apps to ${dimHiddenApps} "
202
+ updateSplashScreen wait " Setting Dim Hidden Apps to ${dimHiddenApps} "
203
+ sudo -i -u $desktopUser defaults write " ${desktopUserHomeDirectory} /Library/Preferences/com.apple.dock.plist" showhidden -bool ${dimHiddenApps}
204
+
205
+ # Configure Auto Hide Dock
206
+ echo " $( date) | Setting Auto Hide Dock to ${autoHideDock} "
207
+ updateSplashScreen wait " Setting Auto Hide Dock to ${autoHideDock} "
208
+ sudo -i -u $desktopUser defaults write " ${desktopUserHomeDirectory} /Library/Preferences/com.apple.dock.plist" autohide -bool ${autoHideDock}
209
+
210
+ # Configure Show Recent Items
211
+ echo " $( date) | Setting Show Recent Items to ${showRecentItems} "
212
+ updateSplashScreen wait " Setting Show Recent Items to ${showRecentItems} "
213
+ sudo -i -u $desktopUser defaults write " ${desktopUserHomeDirectory} /Library/Preferences/com.apple.dock.plist" show-recents -bool ${showRecentItems}
214
+
215
+ # Configure Enable Minimise Icons into Dock Icons
216
+ echo " $( date) | Setting Enable Minimise Icons into Dock Icons to ${enableMinimiseIconsToDock} "
217
+ updateSplashScreen wait " Setting Enable Minimise Icons into Dock Icons to ${enableMinimiseIconsToDock} "
218
+ sudo -i -u $desktopUser defaults write " ${desktopUserHomeDirectory} /Library/Preferences/com.apple.dock.plist" minimize-to-application -bool ${enableMinimiseIconsToDock}
219
+
220
+ # Restart the Dock
212
221
echo " $( date) | Restarting Dock"
222
+ updateSplashScreen wait " Restarting Dock..."
213
223
killall Dock
214
224
215
- echo " $( date) | Writng completion lock to [~/Library/Logs/prepareDock]"
216
- touch " $HOME /Library/Logs/prepareDock"
225
+ # Write a completion lock file
226
+ echo " $( date) | Writng completion lock"
227
+ touch " ${desktopUserHomeDirectory} /Library/Logs/prepareDock"
217
228
229
+ # Update the swiftdialog Screen
218
230
updateSplashScreen success Installed
219
231
220
- # If this is an ADE enrolled device (DEP) we should launch the Company Portal for the end user to complete registration
221
- if [ " $startCompanyPortalifADE " = true ]; then
222
- echo " $( date) | Checking MDM Profile Type"
223
- profiles status -type enrollment | grep " Enrolled via DEP: Yes"
224
- if [ ! $? == 0 ]; then
225
- echo " $( date) | This device is not ABM managed, exiting"
226
- exit 0;
227
- else
228
- echo " $( date) | Device is ABM Managed. launching Company Portal"
229
- open " /Applications/Company Portal.app"
230
- fi
231
- fi
0 commit comments