2

I'm building a Finder extension for OSX, I want to add a separator to the contextMenu of Finder, but I can't see the separator line:

enter image description here

The separator I want to add is like this:

enter image description here

Here is the related code:

let main = NSMenu() 
let submenu = NSMenu()
let mainDropdown = NSMenuItem(
                title: "Extension menu",
                action: nil,
                keyEquivalent: "")

main.addItem(mainDropdown)
main.setSubmenu(submenu, for: mainDropdown)

let all = NSMenuItem(title: "All",
                         action: nil,
                         keyEquivalent: "")

all.isEnabled = false
submenu.addItem(all)
            
submenu.addItem(.separator())
        

I found this:

"This menu item is disabled. The default separator item is blank space." at https://developer.apple.com/documentation/appkit/nsmenuitem/1514838-separator

So what's the correct way to add a separator with the line?

EssExx
  • 49
  • 6
  • Well, have you tried enabling the separator? – Alexander Jun 13 '22 at 13:27
  • 2
    Yes @Alexander, I tried every settable property of NSMenuItem, including NSMenuItem.isEnabled, like this: let sep = NSMenuItem.separator(); sep.isEnabled = true; submenu.addItem(sep); and got the same result – EssExx Jun 13 '22 at 13:34
  • 1
    Hmmm this looks like it's specific to a finder sync extension, and other users have had that same issue https://stackoverflow.com/q/42537343/3141234 – Alexander Jun 13 '22 at 15:29
  • Right, only happens to the dynamic creation of finder extension contextMenu, since apple's official documentation mentioned "**The default separator item is blank space**", really hard to understand why they do this – EssExx Jun 13 '22 at 15:44
  • That's quite baffling. I suspect it's because what ever IPC they're doing only communicates across limited interface data, not including whether it's a separator or not. Why that would be the case... I have no idea. – Alexander Jun 13 '22 at 15:53
  • But the API allows me to create unlimited complex NSMenuItems, except a simple line separator, I really don't want to suspect either apple treats this bug as a feature, or they want to limit third-party extensions' ability, but just can't imagine why their API would fail to such a simple thing – EssExx Jun 13 '22 at 16:09

0 Answers0