Is there a way to resize Dock in macOS using keyboard shortcuts?

Solution 1:

The approach I ended up taking was a variation of @Paolo's solution, and is simple to implement using a tool like BetterTouchTool (as @blizzrdof77 mentions in his original question).

Instead of preparing two AppleScripts, this single script takes one argument - a numeric value between -1.5 and 1.5 - which determines whether the dock will increase or decrease in size.


The AppleScript:
Create a new file called "change-dock-size.applescript" with the following content:
on run argv
    tell application "System Events"
        -- Get dock size
        set docksize to dock size of dock preferences
        -- Increase or decrease based on argument version
        set docksize to docksize + (item 1 of argv)
        -- Constrain value to 0.1 -- 1.5
        if docksize > 1.5 then docksize = 1.5
        if docksize < 0.1 then docksize = 0.1
        -- Set dock to the new size
        set dock size of dock preferences to docksize
    end tell
end run


Running It From The Command Line:
You can run this from the command line using osascript - like this:

# Increase Dock Size
osascript /path/to/script/change-dock-size.applescript 0.01

# Decrease Dock Size
osascript /path/to/script/change-dock-size.applescript -0.01


Adding Keybindings to BetterTouchTool:
To use this in BTT, add two new shortcuts with the "Execute Terminal Command" action, and use the above examples as the commands (I've provided a screenshot of my setup below). I hope this helps!

Resize Dock in MacOS With BetterTouchTool Using Keybindings Screenshot

Solution 2:

First you have to prepare two AppleScripts, one to increase the size of the Dock and one to decrease.

You may run AppleScript Editor, write and test them.

tell application "System Events"

    -- get dock size (decimal in range 0 -- 1)
    set docksize to dock size of dock preferences

    -- increase version
    set docksize to docksize + 0.05

    -- decrease version (commented)
    -- set docksize to docksize - 0.05

    -- constrain value to 0.1 -- 1.0

    if docksize > 1 then docksize = 1
    if docksize < 0.1 then docksize = 0.1

    -- set dock size
    set dock size of dock preferences to docksize
end tell

The dock size is a value ranging from 0 to 1.

The above script increases / decreases the size by 0.05 steps.

You may choose a different formula according to your needs.


The next steps are

  1. Create and save a new service with Automator that run an AppleScript

  2. Assign a keyboard shortcut to the service created via System Preferences

Do it twice: for the increase and decrease shortcut.


When you create the services with Automator the AppleScripts run are the ones you prepared for increase/decrease the Dock size.


Instructions on how to create the service and assign an AppleScript to run are here:

How do I assign a keyboard shortcut to an AppleScript I wrote?


Bottom note:

Some suggested in the comments to resize the dock by issuing the following terminal commands

defaults write com.apple.dock tilesize -int 32; killall Dock

so I did in the first version of this answer. However this approach involves restarting the Dock application with several drawbacks.

As user3439894 suggested the Dock may be resized via AppleScript using System Events. This way the action takes place faster and more gracefully, so I updated my answer.