Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add files to Dock on macOS using the command line

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.

like image 810
Timur Shtatland Avatar asked Dec 07 '25 10:12

Timur Shtatland


1 Answers

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?

like image 127
Timur Shtatland Avatar answered Dec 10 '25 00:12

Timur Shtatland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!