简体   繁体   中英

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.

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?

dockutil ( brew install dockutil ) works flawlessly.

dockutil --add 'file name.pdf'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM