Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System Tray only (no dock icon) application using C# / Mono on Mac

I'm looking to move one of my C# applications over to Mono for use on the Mac. Currently, I'm trying to figure out how to make it a sort of "background" process, but still have the ability to have GUI elements (I believe this rules out mono-service).

The ultimate goal is this:

  1. Put a tray icon up by the clock for the majority of interactions.
  2. Remove the dock icon that typically comes with a launched application
  3. Have the application run on startup.

In short, just think of how the Dropbox app works. I want that type of GUI, but with a Mono / Mac app.

I believe this is typically accomplished by setting LSUIElement = 1 in the application bundle's Info.plist. However, I've had no luck with it. I think it may have something to do with the mono command launching my application from within the app bundle. Once the app launches mono I'm assuming it doesn't cascade to further application launches. That is a pure guess, though.

Does anyone have any ideas on this? Thanks.

like image 505
jocull Avatar asked Dec 11 '10 01:12

jocull


1 Answers

I have your answer:

First, to add a Status bar icon (alternative of Notify Icon in Win Forms):

        NSStatusItem sItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
        sItem.Menu = notifyMenu;
        sItem.Image = NSImage.FromStream(System.IO.File.OpenRead(NSBundle.MainBundle.ResourcePath + @"/notify-icon.icns"));
        sItem.HighlightMode = true;

notifyMenu is your instance of NSMenu as a means of context menu strip for your notify icon.

and put your ICNS file made using Icon Composer in your project files and flag it as Content. (right click->build action->content)

Now It is time to remove dock icon:

on your info.plist file. make a new Boolean type item and name it "LSUIElement" and set the value to YES.

Hope it helps. Regards, Peyman Mortazavi

like image 125
Peyman Avatar answered Oct 10 '22 01:10

Peyman