10

I'm new to OSX development (I've done a little iOS stuff, but this is my first OSX app, and my first Swift app).

I've found several tutorials for how to make a MenuBar app with just a simple list of menu items, like the following:

simple menu

But I'm looking for something more like Evernote's, or Google Drive's, or Mint's MenuBar window:

window

I believe that to do something like the latter, I need a regular NSWindow that is just toggled by clicking the status item (right?), but how do I go about positioning the window the way Evernote & Google do?

I've found this question that gives a couple of ways to get the status item position, if using an Objective C app, but I'm not sure how to translate that to a Swift app. For example, one answer suggests using the following to get the frame of the status item after clicking on it:

[[[NSApp currentEvent] window] frame]

but, in Swift, NSApp.currentEvent does not have a member named "window"...

Does anyone know of any example MenuBar apps, written in Swift, that have more than just a simple list of menu items? Is such a thing simply not possible with Swift, yet?


UPDATE:
Since the examples and starter apps that do this kind of thing in Objective C are abundant, and there's little or nothing on how to do it in Swift, I ended up abandoning the Swift route and built an Objective C app, instead. I used this one as a starter: https://github.com/shpakovski/Popup. It was very quick/easy to get started and ended up being a lot less work than a Swift app would have been.

Maybe one day when Swift is more mature, I'll try another one in that language.

Community
  • 1
  • 1
Troy
  • 21,172
  • 20
  • 74
  • 103
  • Hopefully Swift 2 will deliver your request... – Ahmad N. Chatila Jun 11 '15 at 16:55
  • @troy, can you link to those tutorials you found about the mac apps with the "simple list of menu items"? – MoralCode Jun 09 '16 at 02:32
  • @DeveloperACE, it was long enough ago that I don't have the specific tutorials anymore. A google search for "Swift MenuBar app" will bring up a bunch though. – Troy Jun 15 '16 at 23:06
  • @Troy thank you. I think I managed to find some good ones that I linked to in my recent commit names for my github project: www.github.com/DeveleoperACE/TinyReminders – MoralCode Jun 16 '16 at 02:18
  • 1
    [This 2017 article](https://www.raywenderlich.com/165853/menus-popovers-menu-bar-apps-macos) explains in detail how to do this. – Brecht Machiels Apr 30 '18 at 09:30

1 Answers1

0

Actually, NSApplication.sharedApplication().currentEvent?.window seems fine.

Bell App Lab
  • 818
  • 6
  • 14