Hi,
I am experimenting with the excellent macoslib, and would like to make a simple modification.
I have the following code in the NSStatusItem’s open event, which creates an NSStatusItem with one option:
[code] dim bar as NSStatusBar = NSStatusBar.SystemStatusBar
item1 = bar.CreateStatusItem(NSStatusBar.NSVariableStatusItemLength, AddressOf StatusItemHandler)
item1.title = “MyApp”
item1.highlightMode = True
item1.Image = NSImage.StatusAvailable
item1.AlternateImage = NSImage.StatusPartiallyAvailable
item1.ToolTip = “This is a NSStatusItem”
dim mmenu1 as new NSMenu
call mmenu1.Append(“Option 1”)
item1.menu = mmenu1[/code]
And the following code in the StatusItemHandler method, which appends the selected item into a text area:
TextArea1.appendText "Selected menu """+hitItem.Title+""""+endOfLine
Could someone please tell me what I need to change in order to have NO items in the NSStatusItem, and have the method execute when I click on the actual NSStatusItem icon in the OS X menubar (as opposed to item 1)?
I obviously have to delete the call mmenu1.Append(“Option 1”) line of code, but am not sure how or where I put the required modification?
I think* highlightMode needs to be false. I don’t know how you handle the click action with Xojo.
AlternateImage is used for the clicked icon though, I don’t know what PartiallyAvailable means; just a heads up that AlternateImage isn’t an indeterminate state.
*From old memory, haven’t checked, researched, or even opened my NSStatusItem xcode project.
Not able to edit post, but I just remembered what highlightMode was for.
It’s the automatic inverted state (blue background for the status item and displaying AlternateImage)
Right, you have to set the menu to nil, then set the action for the statusItem rather than a menu. The actionDelegate will fire when you click the status icon.
One final question:
Is it acceptable to leave the StatusItem in the OS X menubar after my app has quit, and then if the StatusItem is clicked, use an if statement to determine if my app is open, and if not - open it?
Or is there some reason this would not work / should not be performed?
The statusItem has to be owned by a process, could be your app, or a helper app. In either case the StatusItem will close when the owner quits. If you create it from a helper app, the helper could be made to relaunch at every login and only open the main app when the user clicks the StatusItem. That’s how iChat does it and seems to be the preferred solution if that’s what you’re looking to do.