Reputation: 12465
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.
Upvotes: 3
Views: 2158
Reputation: 7163
dockutil
works flawlessly. Download the .pkg
from their github Releases page.
Upvotes: 2
Reputation: 12465
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?
Upvotes: 4