Category filter
Script to customize Dock preferences on Mac
The Dock on macOS devices is a small panel that allows you to quickly access files, folders, and applications. Apple provides various options to customize the position, Dock size, and animation effects of the Dock using the Dock and Menu Bar tab under System Preferences. However, configuring the Dock on multiple endpoints can be a cumbersome task for the IT department of any organization. Execute a custom script on target endpoints to remotely configure Dock settings on a granular level with Hexnode UEM.
Scripting Language – Bash
File extension – .sh
Show active apps
Execute the command below to display only the currently running apps in the Dock.
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.dock static-only -bool true' killall Dock |
Replace true
with false
to reset to defaults.
Change Dock position
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.dock orientation -string <position>' killall Dock |
The orientation
property specifies the orientation of the Dock on the home screen. Replace <position>
with either of the values left
, right
, or bottom
to align the Dock on the home screen with respect to it.
Single app mode
The single app mode displays only the application that is currently in use. All other open applications and windows will be minimized into the Dock.
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.dock single-app -bool true' killall Dock |
Change Dock size
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.dock tilesize -integer <dock size>' killall Dock |
Replace <dock size>
with an integer indicating the Dock’s preferred size. The lesser the number, the smaller the icon size. Most Macs appear to have a default size of around 48. You can go as low as 1, making the dock difficult to access.
Change Dock animation style
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.dock mineffect -string <effect name>' killall Dock |
Replace <effect name>
with either of the values suck
, gene
or scale
, which indicate the various app minimization effects supported by Apple.
Add apps
The script below adds the specified applications to the Dock.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/bash LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults delete com.apple.dock persistent-apps' dock_item() { printf '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>%s</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>', "$1" } <app1>=$(dock_item <app1 path>) <app2>=$(dock_item <app2 path>) sudo su $LOGGED_USER -c "defaults write com.apple.dock persistent-apps -array '$<app1>' '$<app2>'" killall Dock |
Replace <app1>
with the name of the application you want to add to the Dock and <app1 path>
with the app path. You can add more apps to the Dock using the same format.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/bash LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults delete com.apple.dock persistent-apps' dock_item() { printf '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>%s</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>', "$1" } notes=$(dock_item /System/Applications/Notes.app) screenshot=$(dock_item /System/Applications/Utilities/Screenshot.app) sudo su $LOGGED_USER -c "defaults write com.apple.dock persistent-apps -array '$notes' '$screenshot'" killall Dock |
The above script adds the Notes and Screenshot apps to the Dock.
Reset to default state
Executing the command below will reset the Dock to the default state.
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults delete com.apple.dock' killall Dock |
Remove apps
Executing the script below will remove the specified app from the Dock. The app remains installed on the device and can be accessed via other methods.
1 2 |
#!/bin/bash /path/to/dockutil --remove 'App Name' --allhomes |
For example,
/usr/local/bin/dockutil --remove 'FaceTime' --allhomes
Mask hidden apps
Executing the script below will dim the icon of the hidden application. This script comes in handy when you are using the keyboard shortcut Command (⌘) + H to hide an application on a Mac. When you do so, the application that you are hiding will appear as a dimmed icon in the dock, helping you differentiate it from the other icons available on the dock. However, the apps that were hidden before the script execution won’t be dimmed.
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.Dock showhidden -boolean yes;' killall Dock |
In the above script, if you specify ‘no’ next to the ‘-boolean’ option, the hidden apps won’t be dimmed.
Disable auto hide delay or modify auto hide animation duration
This script works only if the “Automatically hide and show the Dock” setting is enabled on the device end. By executing the script below, you can either disable the delay or adjust the duration within which the auto hide animation should complete. The auto hide animation duration depends on the integer value given in the script. A value of ‘0’ indicates no delay, ‘1’ indicates the Dock will take 1 second to complete the auto-hide animation, ‘2’ indicates the Dock will take 2 seconds to complete the auto-hide animation.
1 2 3 |
LOGGED_USER=`stat -f%Su /dev/console` sudo su $LOGGED_USER -c 'defaults write com.apple.dock autohide-time-modifier -float 2;' killall Dock |