# 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](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/) on target endpoints to remotely configure Dock settings on a granular level with Hexnode UEM.

Scripting Language – Bash

File extension – .sh

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

Show active apps 
-----------------

Execute the command below to display only the currently running apps in the Dock.

Script to show active apps on the Dock

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.dock static-only -bool true' killall 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 
---------------------

Script to change the Dock position

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.dock orientation -string <position>' killall Dock 

   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.

Script to initiate single app mode

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.dock single-app -bool true' killall 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
----------------

Script to change the Dock size

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.dock tilesize -integer <dock size>' killall Dock 

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

Script to change app minimization animation

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.dock mineffect -string <effect name>' killall Dock 

   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.

Script to add apps to the Dock

\#!/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 

   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:

Script to add Notes and Screenshot apps to the Dock

\#!/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" } Launchpad=$(dock\_item /System/Applications/Launchpad.app) Safari=$(dock\_item /Applications/Safari.app) GoogleChrome=$(dock\_item "/Applications/Google Chrome.app") Slack=$(dock\_item /Applications/Slack.app) Zoom=$(dock\_item /Applications/zoom.us.app) Reminders=$(dock\_item /System/Applications/Reminders.app) Notes=$(dock\_item /System/Applications/Notes.app) SystemPreferences=$(dock\_item "/System/Applications/System Preferences.app") sudo su $LOGGED\_USER -c "defaults write com.apple.dock persistent-apps -array '$Launchpad' '$Safari' '$GoogleChrome' '$Slack' '$Zoom' '$Reminders' '$Notes' '$SystemPreferences'" Killall Dock

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

  \#!/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"

}

Launchpad=$(dock\_item /System/Applications/Launchpad.app)

Safari=$(dock\_item /Applications/Safari.app)

GoogleChrome=$(dock\_item "/Applications/Google Chrome.app")

Slack=$(dock\_item /Applications/Slack.app)

Zoom=$(dock\_item /Applications/zoom.us.app)

Reminders=$(dock\_item /System/Applications/Reminders.app)

Notes=$(dock\_item /System/Applications/Notes.app)

SystemPreferences=$(dock\_item "/System/Applications/System Preferences.app")

sudo su $LOGGED\_USER -c "defaults write com.apple.dock persistent-apps -array '$Launchpad' '$Safari' '$GoogleChrome' '$Slack' '$Zoom' '$Reminders' '$Notes' '$SystemPreferences'"

Killall Dock

   

 

  

The above script adds the following apps to the dock:

1. Launchpad
2. Safari
3. Google Chrome
4. Slack
5. Zoom
6. Reminders
7. Notes
8. System Preferences

 Notes:- The currently opened apps and certain permanent apps like *Finder* and *Bin* will be retained in the Dock.
- Make sure the apps are installed on the device before executing the script. The dock shows a “?” mark in the corresponding position if the apps are not present.
- Enclose the app path within double quotes if the app name contains 2 or more words separated by spaces. For instance, consider the case of how the “Google Chrome” app is specified in the above script.

 

Reset to default state 
-----------------------

Executing the command below will reset the Dock to the default state.

Script to reset the Dock to the default state

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults delete com.apple.dock' killall Dock 

   1

2

3

  LOGGED\_USER=`stat -f%Su /dev/console`

sudo su $LOGGED\_USER -c 'defaults delete com.apple.dock'

killall Dock 

   

 

  

Remove apps
-----------

 Pre-requisites:1. This script requires Homebrew and dockutil packages to be installed on the devices.
2. You can either use the [Mac Live Terminal](https://www.hexnode.com/mobile-device-management/help/how-to-enable-live-terminal-on-your-macos-devices/) or the device’s built-in Terminal window to install them. 
    - For devices running **versions below macOS 12.3**, the following set of commands helps you with it. Commands to install Homebrew and dockutil
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install dockutil 
        
           1
        
        2
        
        
        
          /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
        
        brew install dockutil
    - For devices running **macOS version 12.3 or later**, the following set of commands will help you install dockutil. Commands to install Homebrew and dockutil
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        curl -sL "https://github.com/kcrawford/dockutil/releases/download/3.0.2/dockutil-3.0.2.pkg" -o /tmp/dockutil.pkg sudo installer -pkg "/tmp/dockutil.pkg" -target / rm /tmp/dockutil.pkg 
        
           1
        
        2
        
        3
        
        
        
          curl -sL "https://github.com/kcrawford/dockutil/releases/download/3.0.2/dockutil-3.0.2.pkg" -o /tmp/dockutil.pkg 
        
        sudo installer -pkg "/tmp/dockutil.pkg" -target /
        
        rm /tmp/dockutil.pkg

 

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.

Script to remove app from Dock

\#!/bin/bash /path/to/dockutil --remove 'App Name' --allhomes 

   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.

Script to mask hidden apps

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.Dock showhidden -boolean yes;' killall Dock 

   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.

Script to kill or delay auto hide

LOGGED\_USER=`stat -f%Su /dev/console` sudo su $LOGGED\_USER -c 'defaults write com.apple.dock autohide-time-modifier -float 2;' killall Dock 

   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 

   

 

  

 Notes:- The above commands apply to the logged-in user at the time of the script execution.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.