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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With