Unable to set submenu for NSMenuItem (FinderSync extension)

I'm trying to create a cascade submenu for a Finder Sync extension in Swift/Cocoa. I have the following code:

override func menuForMenuKind(menuKind: FIMenuKind) -> NSMenu! {
    let m = NSMenu(title: "")
    let mi1 = NSMenuItem(title: "item1", action: nil, keyEquivalent: "")
    let mi11 = NSMenuItem(title: "item11", action: nil, keyEquivalent: "")

    let m2 = NSMenu(title: "")
    let mi2 = NSMenuItem(title: "item2", action: nil, keyEquivalent: "")
    m2.addItem(mi2)

    m.addItem(mi1)
    m.addItem(mi11)
    m.setSubmenu(m2, forItem: mi1)
    return m
}

So what I'm trying to achieve is:

item1->
       item2 
item11

So what I actually get is a flat item1 and item11 menu list.

Any hints?


I filed a bug with Apple (#18810635), got a response that it's a duplicate of (#18531883) which is still open.

Posted the copy of the filing at OpenRadar http://openradar.appspot.com/radar?id=5772557445758976 , tweeted to a developer advocate.

If anyone knows the fate of #18531883 - this is core raison d'être for Finder Sync Extensions?

I've upgraded the project to Swift 2.0, and finally made a working submenu. Posting the solution:

override func menuForMenuKind(menuKind: FIMenuKind) -> NSMenu! {
    let main = NSMenu()
    let submenu = NSMenu()
    let mainDropdown = NSMenuItem(title: "Some option group", action: nil, keyEquivalent: "")
    main.addItem(mainDropdown)
    m.setSubmenu(submenu, forItem: mainDropdown)


    submenu.addItem(NSMenuItem(title: "Option 1", action: nil, keyEquivalent: ""))
    submenu.addItem(NSMenuItem(title: "Option 2", action: nil, keyEquivalent: ""))
    return main
}

This will only work on Mac OS 10.11+, 10.10.5 still has the bug being unable to generate a submenu. So a good appraoch is generating a flat menu for < 10.11, and a cascade starting from el capitan.

osx, I am trying to create a waterfall submenu for a Finder sync extension in Swift / Cocoa. I have the following code: override function� NSMenuItem; submenu. Language: Language: { get set} Discussion. The The default implementation of the NSMenu Item class raises an exception if a Submenu

func constructMenu() {
        let main = NSMenu()
        let submenu = NSMenu()
        let mainDropdown = NSMenuItem(title: "Some option group", action: nil, keyEquivalent: "")
        main.addItem(mainDropdown)
        main.setSubmenu(submenu, for: mainDropdown)


        submenu.addItem(NSMenuItem(title: "Option 1", action: nil, keyEquivalent: ""))
        submenu.addItem(NSMenuItem(title: "Option 2", action: nil, keyEquivalent: ""))




       // myList.setSubmenu(mylist2, for: myList)


        statusItem.menu = main
    }

osx, osx - Unable to set submenu for NSMenuItem (FinderSync extension) -. i'm trying create cascade submenu finder sync extension in swift/cocoa. 25 Unable to set submenu for NSMenuItem (FinderSync extension) Oct 14 '14 22 Pass command line parameters to uwsgi script Feb 10 '14 6 sending data from angularjs to django May 9 '12

Finder Sync Extensions do not support submenus in versions before macOS 10.11.

This is stated in the code docs when you examine the FIFinderSyncProtocol header:

Specific menu item properties are used: title, action, image, and enabled. Starting in 10.11: tag, state, and indentationLevel also work, and submenus are allowed.

optional func menu(for menu: FIMenuKind) -> NSMenu?

rdar://18810635: Submenu does not work in FinderSync extensions, Create FinderSync Extension (firstly create an OSX App, then create a new / unable-to-set-submenu-for-nsmenuitem-findersync-extension� A menu item (that is, an object conforming to the NSMenuItem protocol) that controls a Menu. The method sets the action of an Item to submenu Action(_:) . See Also

无法为NSMenuItem设置子菜单(FinderSync扩展), 我正在尝试为Swift / Cocoa中的Finder Sync扩展创建级联子菜单.我有以下 Unable to set submenu for NSMenuItem (FinderSync extension). A Boolean value that indicates whether the menu item has a submenu.

[OS - macOS] Finder Sync Extensions - 편집 개발블로그, Finder Sync Extension In OS X, the Finder Sync extension point lets you Unable to set submenu for NSMenuItem (FinderSync extension). I'm implementing a Finder Sync extension, and have encountered some weird issues with my FIFinderSync implementation. The callback beginObservingDirectoryAtURL is not always called. Usually, when its not called its for the first or second level under my root folder.

Menu Anatomy - Menus - macOS, It's important for people to be able to browse the contents of all menus to learn A submenu is a menu item that operates as a menu, displaying a set of nested Scrolling menus have items that extend beyond the top or bottom edge of the screen. For developer guidance, see the isAlternate property of NSMenuItem. The NSMenuItem class provides a reference implementation suitable for most uses. when set to YES, Sets the submenu of the receiver.

Comments
  • Could you post your log (from Console)? I'm experiencing the exact same issue..
  • hi! I used your question to build my submenu items and I managed to make it work.
  • #Nuno Gonzales - have you tried using it in FinderSync extension or just a regular submenu?
  • I'm having the same problem. Kind of annoying...
  • Anybody have an update on this issue? I tried to find the status of 18531883 on OpenRadar, but it doesn't seem to exist in their database.
  • Hi, do you know how to add a menu item like the Move to Dropbox menu item here? In the docs it is mentioned that you need to implement the same menuForMenuKind: method passing the menu kind to it as an argument. Do you know from hwere I should be calling that method with the parameter?
  • You don't explicitly call it, menuForMenuKind: should be implemented for FIFinderSync interface. When You register the directories, FinderSync will call this method each time a user opens a files context menu.
  • Oh I see. What do you mean by registering directories? Can you please tell me how to do that? Or point me to a resource you used? Info about Finder Sync is scarce.
  • A Hello World example is available as a template in Xcode. File->New->Target, choose Application Extensions, pick the Finder Sync Extension. Good luck
  • I was already playing around with the boilerplate project but still having the issue. I'll post a separate question then. Thanks.