Remove macOS Dock icon with a command in Terminal

I'm trying to find the terminal command which can remove an icon from the dock, but I can't find the solution.

I tried the defaults read / defaults write command but it doesn't seem to have the delete function.

The plist is com.apple.dock.

It's curious because the graphical function do it well, and I searched in the console, I don't find what the graphical function call.. I need to do find it to create a removal script..

defaults read com.apple.dock

Remove icon from dock with the graphic function

If someone have a solution, it could be cool.

Thanks


Solution 1:

I recommend using dockutil for this. You can either download and install this directly from github, or you can install it using Homebrew with the command

brew install dockutil

Once installed, you can use a command like this to remove an app from the dock

dockutil --remove 'Microsoft Excel'