3

How can I add a file to the Dock in macOS using the Terminal?

Typically this is done using Finder, by dragging and dropping the file icon into the Dock. I am looking for a programmatic way using the command line / Terminal.

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47

2 Answers2

4

To add file /path/to/file name.pdf to the right end of the Dock use the following while replacing file:///path/to/file%20name.pdf with the correct fully qualified pathname:

defaults write com.apple.dock persistent-others -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>file:///path/to/file%20name.pdf</string><key>_CFURLStringType</key><integer>15</integer></dict><key>file-type</key><integer>32</integer></dict><key>tile-type</key><string>file-tile</string></dict>"; killall Dock

This answer is courtesy of user3439894, and was deeply buried in the comments of a related question about adding apps to the Dock: How to create Dock entries via Terminal in macOS Sierra?

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
2

dockutil works flawlessly. Download the .pkg from their github Releases page.

ijoseph
  • 6,505
  • 4
  • 26
  • 26