Skip to content

Commit 1626ed8

Browse files
Updated dock script
1 parent 1a5917e commit 1626ed8

File tree

3 files changed

+99
-100
lines changed

3 files changed

+99
-100
lines changed

img/dockv2.png

6.2 MB
Loading

macOS/Config/Dock/addAppstoDock.sh macOS/Config/Dock/addAppstoDockv2.sh

+92-92
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,49 @@
2727
## Lines 146 onwards confiure Dock look and feel, uncomment as necessary
2828
##
2929

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
3239
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-
3740

41+
# Define log and start logging...
42+
log="/var/tmp/addAppstoDock.log"
3843
exec &> >(tee -a "$log")
3944

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
4159

4260
echo "$(date) | Script has already run, nothing to do"
4361
exit 0
4462

4563
fi
4664

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+
4773
# workaround for Ventura (macOS Ver 13.x) System Settings.app name change
4874
if [[ -a "/System/Applications/System Settings.app" ]]; then settingsApp="System Settings.app"; else settingsApp="System Preferences.app"; fi
4975

@@ -54,20 +80,14 @@ dockapps=( "/System/Applications/Launchpad.app"
5480
"/Applications/Microsoft Excel.app"
5581
"/Applications/Microsoft PowerPoint.app"
5682
"/Applications/Microsoft OneNote.app"
57-
"/Applications/Microsoft Teams Classic.app"
83+
"/Applications/Microsoft Teams.app"
5884
"/Applications/Visual Studio Code.app"
5985
"/Applications/Company Portal.app"
6086
"/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app"
6187
"/System/Applications/App Store.app"
6288
"/System/Applications/Utilities/Terminal.app"
6389
"/System/Applications/$settingsApp")
6490

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-
7191
echo ""
7292
echo "##############################################################"
7393
echo "# $(date) | Starting install of $appname"
@@ -90,7 +110,7 @@ function updateSplashScreen () {
90110
if [[ -a "/Library/Application Support/Dialog/Dialog.app/Contents/MacOS/Dialog" ]]; then
91111

92112

93-
echo "$(date) | Updating Swift Dialog monitor for [$appname] to [$1]"
113+
echo "$(date) | Updating Swift Dialog monitor for [$appname] to [$1]"
94114
echo listitem: title: $appname, status: $1, statustext: $2 >> /var/tmp/dialog.log
95115

96116
# Supported status: wait, success, fail, error, pending or progress:xx
@@ -99,32 +119,6 @@ function updateSplashScreen () {
99119

100120
}
101121

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
128122

129123
START=$(date +%s) # define loop start time so we can timeout gracefully
130124
echo "$(date) | Looking for required applications..."
@@ -140,7 +134,6 @@ while [[ $ready -ne 1 ]];do
140134
missingappcount=0
141135

142136
for i in "${dockapps[@]}"; do
143-
checkAndSetInstalledMSTeamsPath "$i"
144137
if [[ -a "$i" ]]; then
145138
echo "$(date) | $i is installed"
146139
else
@@ -162,70 +155,77 @@ while [[ $ready -ne 1 ]];do
162155

163156
done
164157

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+
165166
updateSplashScreen wait "Installing"
166167

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
170168

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
171174
echo "$(date) | Adding Apps to Dock"
172175
for i in "${dockapps[@]}"; do
173-
checkAndSetInstalledMSTeamsPath "$i"
174176
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"
177178
updateSplashScreen wait "Adding $i to Dock"
179+
sudo -i -u $desktopUser /usr/local/bin/dockutil --add "$i" --no-restart > /dev/null 2>&1
178180
fi
179181
done
180182

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
191184
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
212221
echo "$(date) | Restarting Dock"
222+
updateSplashScreen wait "Restarting Dock..."
213223
killall Dock
214224

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"
217228

229+
# Update the swiftdialog Screen
218230
updateSplashScreen success Installed
219231

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

macOS/Config/Dock/readme.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
This script is an example showing how to use [Intune Shell Scripting](https://docs.microsoft.com/en-us/mem/intune/apps/macos-shell-scripts) to modify the macOS dock. In this instance the script has a list of apps that it waits to be present on the device before clearing the dock and adding the apps defined.
44

5-
![Desktop Image](https://github.com/microsoft/shell-intune-samples/raw/master/img/desktop.png)
5+
![Desktop Image](https://github.com/microsoft/shell-intune-samples/raw/master/img/dockv2.png)
66

77
## Scenario
88

99
This scripts intended usage scenario is to be deployed during the initial app enrolment. It will wait until all of the apps are present before configuring the users dock.
1010

11+
>IMPORTANT
12+
>>This updated script uses [dockutil](https://github.com/kcrawford/dockutil), without this being installed the script will fail. Download the latest version and deploy via [Intune Unmaged PKG](https://learn.microsoft.com/en-us/mem/intune/apps/macos-unmanaged-pkg).
13+
14+
>>This updated script no longer runs as the end user, you need to ensure that you deploy it to **run as root**.
15+
1116
The script searches for Apps listed in the DockItems array and once they are all present it adds them to the Dock in the order they appear in the list. Edit the list as appropriate for your use.
1217

1318
Add Applications to the Dock
@@ -27,16 +32,10 @@ dockapps=( "/Applications/Microsoft Edge.app"
2732
"/System/Applications/System Preferences.app")
2833
```
2934

30-
Add Network Shares to the Dock ()
31-
```
32-
netshares=( "smb://192.168.0.12/Data"
33-
"smb://192.168.0.12/Home"
34-
"smb://192.168.0.12/Tools")
35-
```
3635

3736
## Script Settings
3837

39-
- Run script as signed-in user : Yes
38+
- Run script as signed-in user : No
4039
- Hide script notifications on devices : Not configured
4140
- Script frequency : Not configured
4241
- Mac number of times to retry if script fails : 3

0 commit comments

Comments
 (0)