             activateDevMode(sender)
         }
         else{
-            
+            statusItem?.menu = appMenu
         }
+    }
+    
+  //MARK: - NSMenuDelegate
+    func menuDidClose(menu: NSMenu) {
+        statusItem?.menu = nil
     }
 }
 

import Appkit

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var appMenu: NSMenu!
    var statusItem:NSStatusItem?

        statusButton?.target = self;
        statusButton?.action = "barButtonMenuPressed:"
        statusButton?.sendActionOn(Int((NSEventMask.LeftMouseDownMask | NSEventMask.RightMouseDownMask).rawValue))
        
        appMenu.delegate = self
    }

    func activateDevMode(sender: AnyObject) {
