NSDockTilePlugin tutorial....

I'm trying to write a game for MacOS and I'd like to be able to provide a menu option, when the app isn't running, that allows them to jump straight back to the last game level they were playing. My limited understanding is that NSDockTilePlugins is the correct way to do this, as from MacOS 10.6, but I cannot find an actual Objective C tutorial from Apple on how to implement this correctly?

Is this the only way to implement non-runtime menus? Can anyone please point me in the right direction?

Answered by domaal in 398759022

After further Googling I found a github repo that contained a DockTilePlugin Sample that was 7 years old. I have updated the sample so that it builds and runs with XCode 11 and enhanced it slightly to suit my needs, as I wanted to be able to dynamically update the App's DockTile menu when the app isn't running.


I hope others find this update sample useful.


The updated project, with the original author's ReadMe.rtf can be found on GitHub here -


https://github.com/CartBlanche/MacDockTileSample


If someone with more Objective C experience can look over the code and tell me if there are better ways of doing things, I'll update the code, or send me a PR.

Hope this may help:


https://stackoverflow.com/questions/33681565/how-can-i-add-a-menu-to-the-application-in-the-dock



Adding Static Menu Items With a Nib File

If your application needs to add static items to the application’s Dock tile’s menu, you can provide those items in a nib file. To do this, perform the following steps.

  1. Launch Interface Builder.
  2. Create a new nib file for your menu.
  3. Create a menu that includes the items you wish to add to the menu.
  4. Connect the dockMenu outlet of the file’s owner (which by default is NSApplication ) to your menu.
  5. Add the nib name to the Info.plist , using the key AppleDockMenu . The nib name is specified without an extension.


Note: for point 4, right click on application (in file browser left pane). You will see a dockMenu outlet (below delegate) and then connect to the menu.


Dynamically Adding Menu Items With the Application Delegate

An application can also provide items dynamically to your application’s Dock tile’s menu. To do this, your application’s delegate object provides a applicationDockMenu: method. This method returns a NSMenu object that provides all the custom menu items you wish to add to the menu. If you also provided a menu using a nib file (see Adding Static Menu Items With a Nib File), any menu returned by your delegate replaces the menu provided in the nib file.


Hi Claude, thanks for taking the time to reply.

The dynamic solution works at runtime and I used that example to get it working for mine. But if you have a look at Xcode when it is totally shut-down, it still shows a list of most recently opened projects. Some people call them Jump Lists. My limited understanding is that this uses NSDockTilePlugins and other than the documentation here - https://developer.apple.com/documentation/appkit/nsdocktileplugin?language=objc - there really is no step by step guide showing how they can be implemented. The docs say that from 10.6, this is the "preferred" method.

Yes, I read the same (have to use NSDockTilePlugins) in the doc, which is not exptremely helpful.


I found this old SO

https://stackoverflow.com/questions/13984500/dock-tile-plug-in-not-working


Which points to an Apple doc which does not exist anymore in Archive.

http://developer.apple.com/library/mac/#samplecode/DockTile/Listings/DockTilePlugIn_DockTilePlugIn_m.html


Maybe you could

- use developer contact to ask them where this sample code may be found

- if unsuccesful, burn a DTS ticket

ANd if you find a solution, that will be great to report here.


Good luck.

Yes I found that SO and the link. I've added a comment to the SO, to ask the OP to upload the working version of the sample to a repo somewhere. We'll see if he's still around and still uses SO.


I'm unfamiliar with how to use either developer contact or how to burn a DTS ticke. Do you have links on how to do both?

Waiting for SO reply is a good start.


For contact, you have the link at the extreme bottom of this page.

Contact Us


You should start with contact.


For DTS, click on Account in the top banner of this page on the right.

Then select "Code Level Support" on the left pane.


You have up to 2 free DTS call per year, so should use with care. But they are really efficient.

Thanks for all your help!


As soon as I find a solution, I'll post back to this thread, as the info is as rare as hen's teeth.

Accepted Answer

After further Googling I found a github repo that contained a DockTilePlugin Sample that was 7 years old. I have updated the sample so that it builds and runs with XCode 11 and enhanced it slightly to suit my needs, as I wanted to be able to dynamically update the App's DockTile menu when the app isn't running.


I hope others find this update sample useful.


The updated project, with the original author's ReadMe.rtf can be found on GitHub here -


https://github.com/CartBlanche/MacDockTileSample


If someone with more Objective C experience can look over the code and tell me if there are better ways of doing things, I'll update the code, or send me a PR.

I've posted a link to a gihub code sample that works, but has been in moderation over night.

What is the rough time frame for moderators to approve posts?

Have you seen this?


https://developer.apple.com/library/archive/samplecode/DockBrowser/Introduction/Intro.html#//apple_ref/doc/uid/DTS10000695


While its main focus is using bonjour and net, the customization of the dock tile is also a part of it.

Hi Jana,

If I'm not mistaken that code is about updating the DockTile Menu, while the application is running. While what I'm looking for is updating the DockTile menu while the application is NOT running. Which requires a NSDockTilePlugin implementation. You can see this by making sure System Preferences is not running, then Control->Click the dock tile, it still displays a comprehensive menu, even though System Preference is not running. This then allows you to Jump to specific area within Preferences and only at that point does it then launch System Preferences itself and short-cut you to the right place. That is the behavior I'm looking for 🙂

Because I have about 120 student papers to grade over the next few days, I have been thinking about your problem! For some strange reason, Objective C is a way for me to relax. Anyway, some thoughts:


From the NSDocumentController documentation:


https://developer.apple.com/documentation/appkit/nsdocumentcontroller?language=objc


"In some situations, it is worthwhile to subclass

NSDocumentController
in non-
NSDocument
-based apps to get some of its features. For example, the
NSDocumentController
management of the Open Recent menu is useful in apps that don’t use subclasses of
NSDocument
."


If I were designing a game, which I have very little experience doing so, I would probably imagine the game "engine" portion distinctly separate from the data in the games that are played. Meaning this--each game would generate data associated with it (player locations, nerf balls dropped, goals achieved, parts of map explored, etc.). This data would be stored in a separate file and is loaded by the app to either start a new game (default set of data) or resume a game. This is not much different than a text editing app in concept--it's just the data that is different and the way it is displayed is different.


So, I would look at saving games and using the Open Recents feature that is already available when using NSDocumentController. Using this approach would allow you to have many previous games or prior levels achieved in a game saved and available for immediate launch from the dock icon. NSDocumentController gives you control over what, how many, etc. is in the open recents menu.


Just a thought.

It is important to note that apps with Dock Tile plugins are not allowed in the Mac App Store! So don't waste your time on this if you plan to publish your app only in the MAS.

NSDockTilePlugin tutorial....
 
 
Q