bash - 使用 Bash 脚本自定义 macOS 的 Dock
问题描述
我想使用 Bash 脚本(没有 AppleScript)自定义 macOS 的 Dock。
目前我有代码(从这个答案中获取和修改):
#!/bin/bash
defaults delete com.apple.dock persistent-apps
dock_item() {
printf '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>%s</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>', "$1"
}
defaults write com.apple.dock persistent-apps -array \
"$(dock_item /Applications/iTerm.app)" \
"$(dock_item /Applications/Visual\ Studio\ Code.app)" \
"$(dock_item /Applications/Slack.app)" \
"$(dock_item /Applications/Google\ Chrome.app)" \
"$(dock_item /System/Applications/Utilities/Screenshot.app)"
killall Dock
这会更改默认 Dock:
至:
但我也希望它删除垃圾箱旁边的下载文件夹以及出现在运行应用程序的垂直线之间的重复图标(在这种情况下只有 iTerm),这些图标保存/保存在 Dock 中(左侧垂直线)。像这样:
此外,在进行更改后,代码更新 Dock 的方式是杀死 Dock 进程,然后自动重新启动。我觉得应该有一种更快的方法来做到这一点,它不会使 Dock 下降,然后桌面变黑一会儿,打开任何最小化的应用程序,然后使 Dock 上升(录制)。
解决方案
在比较了defaults read com.apple.dock
手动从 Dock 中删除图标之前和之后的打印内容后,我注意到我只需要删除recent-apps
(对于重复的图标)和persistent-others
(对于文件夹)键:
defaults delete com.apple.dock recent-apps
defaults delete com.apple.dock persistent-others
推荐阅读
- ios - 如何在 iOS Safari 上访问完整的相机分辨率?
- r - 难以将数据集中的宽格式转换为整齐的格式
- github - Hydrograph Tool 是否有可用的文档?
- rx-java - RXJava 顺序执行 http 请求
- php - 为什么我会收到 ERR_NAME_NOT_RESOLVED?
- kubernetes - 如何测量 kubernetes POD 内的容器执行时间?
- javascript - Vuejs 动态添加 ref undefined
- linux - “go build”命令后找不到可执行文件/二进制文件
- python-3.x - 如何更改选择器scrapy?
- python - 在不同的列中分离 Python Web 抓取的数据 (Excel)