Display NSPopover above dock icon - cocoa

How can I display an NSPopover above my app's dock icon?

There are two ways to customise the dock menu, based on if your application is running or not. See the Apple documentation for customising it when its open here:
http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/docktasks_cocoa/docktasks_cocoa.html#//apple_ref/doc/uid/TP30000986-CH3-SW1
To summarise, you basically provide a menu in the main application's XIB or storyboard which contains the extra menu options that you want to add to the dock menu.
To customise your Dock icon's menu when the application is not running, see the guide here:
http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/CreatingaDockTilePlug-in/CreatingaDockTilePlug-in.html
Basically, you need to create a plugin which you drop into your application's resource folder. This works very like the original method, but executes inside Finder's dock process.

Related

How to enable auto generation of Window MenuItems (e.g. Tile Window to Left/Right of Screen and Open file with checkmark) in macOS menubar

I am currently creating a macOS menubar for an app without using any interface builder (no XIB/NIB files), just pure code. However I was expecting some items to be auto-generated during the start-up of the app. Items like "Start Dictation", "Emoji & Symbols" under Edit menu were existing as well as the "Enter Full Screen" menu item under the View Menu. But when it comes to Window Menu nothing was automatically generated, only the menu items I've set in the code. Do I have to enable some flags or options when instantiating a Window NSMenu so it automatically generates those items? I am new to macOS development so I feel like I am kind of lost. Thanks in advance.
The Window and Help menus are a little special in that they have their own NSApplication properties, so you will need to set them to your menus so that the system will know what they are.
For example, if you just create a window menu and add it to the main, all you will get are the items that you have provided. If you also set it as the application’s windowsMenu, in addition you will get all the stuff for moving, tab support, etc.
Setting NSApp’s helpMenu is similar, where a Spotlight menu item is added to the menu.

How to reuse NSMenu in different windows?

In Xcode I've created a new Main Menu xib from the Main Menu template. It only contains the main-menu, which I would like to use in my app.
How can I load this Main Menu from this xib-file and use it in my different windows?
You don't need to do anything.
An application's main menu is already global—it's part of the application, not of any individual window. The same menus will appear regardless of which window is active, by default.
You would have to put in some work if you wanted to go the other way and have different menus depending on which window is active.

Menu Bar app being launched by Dock Icon (Mac OS X)

I'm working on a Menu Bar app and I've added the LSUIElement so the icon won't appear in the dock when the app is in use (And also to remove the File, Edit, View etc at the left of the menu bar).
The problem is that I want the app to be launched by the Icon and by adding the LSUIElement the only way to luanch the app is thru xcode.
I've seen that in the Mac app Caffiene it launches by the icon but it doesn't appear in the dock that it's running etc which is excatly what I want/need.
So I was wondering if you guys know how to do this.
Thank you in advance!
If you want to have a dock icon but not show the app as running in the Dock, simply create two applications:
Status Menu Application
This is the actual application that sets up the menu and contains the application's logic. It has LSUIElement set.
Launcher Application
This application has a dock icon. It contains the status menu application in its bundle. Its sole job is to launch the status menu application and then quit itself.
There is a really simple way to do this without creating a separate launcher app. Build your application, which has a status item, as an app bundle. Then, add an entry to the application's Info.plist file
Key: NSUIElement
Value: Number, 1 or Boolean True
NSUIElement tells OSX if the app should display in the Dock or not.

Hiding NSMenu while the dock remains active

I want my app to show his menu on launch only if the user didn't open a file. Now I can't seem to make it work. Hiding the menu makes the dock and the status bar invisible. I want them to still be there, but not with my own menu (e.g. if you open a file from finder, the finder menu is still visible, but my app opens a window that handles the file, and quits if the user cancels or on completion).
I probably didn't explain it well enough, but here's what I did to solve it :
Add this line to the plist of my app (this produces an app without dock icon or menu), the dock and the menu bar will still be there, but won't be changed by the app :
LSUIElement
(And set the checkbox to true).
This makes your app UI-only (it doesn't show his NSMenu nor does it add an icon to the dock, but just shows your GUI.

How do you show the Finder context menu from a Cocoa application?

I have a file listing in my application and I would like to allow people to right-click on an item and show the same contextual menu as Finder does. Is this possible?
The same functionallity but for Windows Explorer is discussed in How do you show the Windows Explorer context menu from a C# application?.
You can't extract the Finder's contextual menu in any stable way, no. Neither can you tell the Finder “show your contextual menu here, as if the user had right-clicked on this item”.
You'll have to make your own.
If I understand the question correctly...
Showing a custom icon and action in your Finder Context Menu is now possible in OS X 10.10 Yosemite via a Finder Sync Extension:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Finder.html

Resources