如何从 Mac OSX Mavericks 的 Dock 中删除应用程序图标?

use*_*562 5 macos icons dock osx-mavericks

我正在编写一个应用程序卸载程序,我想在其中从 Dock 中删除我们应用程序的图标。在安装过程中,使用命令行上的以下命令将图标添加到停靠栏:

sudo -u "$USER" defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/MyApplication.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
sudo -u "$USER" osascript -e 'tell Application "Dock"' -e 'quit' -e 'end tell'
Run Code Online (Sandbox Code Playgroud)

在卸载过程中,我使用以下 shell 脚本从 Dock 中删除图标:

#!/bin/sh
# Get location of entry for our application in Dock
dloc=$(defaults read com.apple.dock persistent-apps | grep file-label\" | awk '/MyApplication/ {print NR}')
dloc=$((dloc - 1))

# Remove this entry from Dock's plist file : com.apple.dock.plist
/usr/libexec/PlistBuddy -c "Delete persistent-apps:$dloc" ~/Library/Preferences/com.apple.dock.plist

# Restart Dock to persist changes
osascript -e 'delay 3' -e 'tell Application "Dock"' -e 'quit' -e 'end tell' -e 'delay 3'
#killall Dock
Run Code Online (Sandbox Code Playgroud)

我可以看到上面的脚本成功地从com.apple.dock.plist plist的persistent-apps中删除了MyApplication的条目。但是重新启动 Dock 后,Dock 仍然具有与之前相同的图标。

有人可以帮忙吗?

谢谢,

小智 5

删除该项目两次即可解决此问题:

#!/bin/sh -
#delete item from com.apple.dock.plist
dloc=$(defaults read com.apple.dock persistent-apps \
    | grep file-label \
    | awk '/Notes/  {printf NR}')
dloc=$[$dloc-1]
echo $dloc
sudo -u $USER /usr/libexec/PlistBuddy \
    -c "Delete persistent-apps:$dloc" \
    ~/Library/Preferences/com.apple.dock.plist

#must delete item from com.apple.dock.plist agian,or won't change
dloc=$(defaults read com.apple.dock persistent-apps \
    | grep file-label \
    | awk '/Photo Booth/  {printf NR}')
#dloc=$(defaults read com.apple.dock persistent-apps \
    | grep _CFURLString "PageManager%209.31.app")
dloc=$[$dloc-1]
echo $dloc
sudo -u $USER /usr/libexec/PlistBuddy \
    -c "Delete persistent-apps:$dloc" \
    ~/Library/Preferences/com.apple.dock.plist
sleep 3
# Restart Dock to persist changes
osascript -e 'delay 3' \
          -e 'tell Application "Dock"' \
          -e 'quit' \
          -e 'end tell'
Run Code Online (Sandbox Code Playgroud)


u62*_*898 1

愚蠢的问题,可能是;-),但是您正在脚本的删除部分中修改正确的用户plist,不是吗?

看起来好像它可以从 /root/Library 而不是 /Users/username/Library 中删除......