简体   繁体   English

使用命令行将文件添加到 macOS 上的 Dock

[英]Add files to Dock on macOS using the command line

How can I add a file to the Dock in macOS using the Terminal?如何使用终端将文件添加到 macOS 中的 Dock?

Typically this is done using Finder, by dragging and dropping the file icon into the Dock.通常这是使用 Finder 完成的,方法是将文件图标拖放到 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:要将文件/path/to/file name.pdf添加到 Dock 的右端,请在使用正确的完全限定路径名替换file:///path/to/file%20name.pdf时使用以下命令:

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?这个答案是由user3439894提供的,并且深深地埋在关于将应用程序添加到 Dock 的相关问题的评论中:如何在 macOS Sierra 中通过终端创建 Dock 条目?

dockutil ( brew install dockutil ) works flawlessly. dockutil ( brew install dockutil ) 完美运行。

dockutil --add 'file name.pdf'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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