Pinning an item on MacOS's dock programatically

I want to pin an item (an app or a .webloc file) in the MacOS dock. Has apple provided an API for this?

I have seen in other forums that it could be done using the following command.

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/location** "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

This command adds the item in the com.apple.dock.plist file, which stores all the items present in the dock. This file is present in ~/Library/Preferences/.

But the dock needs to be killed once first for the item to show as pinned in it after running the command . Killing the dock can have undesirable effects, for example it maximises the minimised apps and files. Is there any way to pin the item without killing the dock?

Has apple provided an API for this?

No.

And given that we’re 20-something years into the Mac OS X project, that should tell you something. The Dock is meant to be under the control of the user. If the user wants to keep your app in the Dock, they have an easy way to do that. You shouldn’t be forcing it on them.

I have seen in other forums that it could be done using the following command.

That technique is not supported.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Got it. The goal wasn't to force pinning of my app on the user but to provide an easier option to pin some children apps installed by the user while using my app, without having to launch them. Thank you for clarifying.

Pinning an item on MacOS's dock programatically
 
 
Q