hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

Add Ability to add Custom Items to Dock Icon Contextual Menu

Open latenitefilms opened this issue 7 years ago • 7 comments

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

latenitefilms avatar Apr 21 '17 15:04 latenitefilms

See: https://developer.apple.com/reference/appkit/nsapplicationdelegate/1428564-applicationdockmenu?language=objc

latenitefilms avatar Apr 21 '17 15:04 latenitefilms

@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).

latenitefilms avatar Apr 25 '17 07:04 latenitefilms

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.

cmsj avatar Apr 25 '17 07:04 cmsj

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!

latenitefilms avatar Apr 25 '17 08:04 latenitefilms

@asmagill - If you do ever go back to hs.menubar, this issue would be awesome to keep in mind too.

latenitefilms avatar Jul 22 '22 01:07 latenitefilms

I'd still love to tackle this at some point too...

latenitefilms avatar Dec 10 '23 22:12 latenitefilms

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.

asmagill avatar Dec 11 '23 09:12 asmagill