MacOS – way to resize Dock in macOS using keyboard shortcuts

customizationdockkeybindingsmacosshortcut

I would like to be able to resize the Dock in macOS strictly using keybindings. Ideally, this would be incrementally and work similar to the way that volume/brightness increase/decrease keys work.

I use BetterTouchTool for most of my gesture/shortcut customizations, and I have been able to achieve just about everything I've needed with it, but this is one thing I've yet to figure out.

Has anyone ever successfully achieved this? If so, what was your approach (software, tools, etc.)?

Best Answer

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