hammerspoon
hammerspoon copied to clipboard
Add Ability to add Custom Items to Dock Icon Contextual Menu
Apps can have custom menu items when you right click on them on the dock. For example, attached is what happens when you right click on the Mail dock icon.
It would be great if this could be controlled via an API in Hammerspoon. Maybe as part of hs.dockicon
?
![screen shot 2017-04-22 at 1 36 00 am](https://cloud.githubusercontent.com/assets/22286696/25285022/30837cdc-26fc-11e7-9108-15daf9edf98e.png)
See: https://developer.apple.com/reference/appkit/nsapplicationdelegate/1428564-applicationdockmenu?language=objc
@cmsj & @asmagill - You could probably just add a function that allows you to "attach" a hs.menubar
(or multiple menus?) to the Dock Icon (in a similar way to how you attach toolbars to webviews).
Looking at the docs, it's not so much about attaching the menu object to the dock, more that our AppDelegate will get a callback when a dock menu object is needed.
It seems like we can re-use hs.menubar objects, we'll just need some hs.menubar API to register one of them with MJAppDelegate so it can return the menu to the Dock as needed. Then there's figuring out how the messages get back to us, and down into the Lua callbacks, when someone clicks on a menu item.
Sweet! Sounds good! If you have the time to give it a bash, that would be amazing. Otherwise, I'm happy to give it a shot sometime over the next few weeks, and you can review (although I'll definitely need some help on the old IRC at some point I'd imagine!). Thank you!
@asmagill - If you do ever go back to hs.menubar
, this issue would be awesome to keep in mind too.
I'd still love to tackle this at some point too...
I know I've been MIA for a bit, but hopefully over the next couple of weeks, I'll have time to actually contribute again and work on the spoons like I proposed 😬
I've revisited my gui toolkit recently, for which the menubar stuff was totally redone from scratch. With the new module, its very easy to create menus to attach to other things, like controls (combo buttons, tabs, etc.) so I don't think this should be too hard. I need to flesh out the documentation and then can give this a look.