How to hide icon menu bar

Hello,

My application displays an icon in the menu bar…

            
            set itemOpenWindow to current application's NSMenuItem's alloc()'s init()
            tell itemOpenWindow to setTitle_("Open window")
            tell itemOpenWindow to setAction_("menubarOpenWindow:")
                    
            set itemSeparator to current application's NSMenuItem's separatorItem()

            set itemQuit to current application's NSMenuItem's alloc()'s init()
            tell itemQuit to setTitle_("Quit")
            tell itemQuit to setAction_("menubarQuitApp:")

            set itemsMenuBar to current application's NSMenu's alloc()'s init()
            tell itemsMenuBar to addItem_(itemOpenWindow)
            tell itemsMenuBar to addItem_(itemSeparator)
            tell itemsMenuBar to addItem_(itemQuit)
            set statusBar to current application's NSStatusBar's systemStatusBar()

            set theItem to statusBar's statusItemWithLength:(current application's NSVariableStatusItemLength)
            set imageMenuBar to current application's NSImage's imageNamed:"IconMenuBar"
            tell theItem to setImage:imageMenuBar
            tell theItem to setHighlightMode_(true)
            tell theItem to setMenu_(itemsMenuBar)

I don’t find how to hide the icon without relaunch the application. Is it possible ?

Thanks!

How abou this?

current application’s NSStatusBar’s systemStatusBar()’s removeStatusItem:statusBar

Thanks Maro but it doesn’t work… :frowning:

Finally found:


current application's NSStatusBar's systemStatusBar()'s removeStatusItem:theItem

:wink:

I don’t think you can hide a menu bar item in the sense you mean, but you can remove it (and then re-add it if it’s needed again). In other words:

tell itemsMenuBar to removeItem:itemOpenWindow
-- the Open Window menu item should disappear
tell itemsMenuBar to insertItem:itemOpenWindow atIndex:1
-- re-inserts the Open Window item at index 1
tell itemsMenuBar to removeAllItems()
-- takes away all of the menu bar items