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

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

Related

How does Dropbox install the App Icon + "Move to Dropbox" global context menu item in Mac OS X Finder?

When Dropbox is installed on Mac OS X, it installs a "Move to Dropbox" context menu item when right-clicking on any item in Finder:
I would like to install a similar menu item for other my own app. Specifically, I would like an "Open in AppName" menu item that allows me to quickly open files in the app without wading through the "Open With..." menu mess.
I have found ways to add Automator services for these actions.
However, these are installed at the bottom of the menu, in "Services". They also do not have an app icon, which is key for quickly visually finding the correct menu item in the list.
I would instead like to exactly replicate the "Move to Dropbox" menu item:
App Icon is displayed.
Near top of context menu, not at the very bottom.
What method does Dropbox use? How can I replicate it for my own app?
Does one need to include code for this menu item in the app itself?
Is it possible for the user to add such a menu item for any app, similar to automator/services, without touching the app's code?
Dropbox is currently using Finder Sync extension. You can do all of that using it. Very simple to integrate and implement.

Display NSPopover above dock icon

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.

Writing an App for OS X that allows users to select app with Contextual Menu item "Open With"

I have a Multimedia App that is for Mac OS X using Xcode.
The languages used are Objective-C, C++ and C.
I want to somehow get my app in the "Open With" contextual menu without having the user do anything. I don't want to "take over" the default association unless the user sets it in the Preferences or takes additional steps.
Any suggestions?
If you add an entry for the document type you'd like to support to your application's Info.plist it should show up in that menu. The easiest way to do this is to select your target and add the type in the Info tab.

Adding static items to "Windows" menu in Cocoa application

I have a application with 2 windows (think like Twitter Timeline and mentions). For now I have been having the menus "Timeline ⌘1" and "Mentions ⌘2" in the "File" menu but this is kind of wrong. So I moved them to the "Windows" menu just by drag and drop.
When I open the application everything is nice, I can see both menu items unter the "Windows" menu. But then when I close for example the Mentions window the menu Item "Mentions ⌘2" disappears and I am not able to open this window anymore.
I have had a look at other applications and most of them have their Menu items to show the windows in the "Windows" menu and they don't disappear either after closing the windows. I am aware of the fact that Cocoa does soma magic with the "Window" menu item and it is quite ok in doing so (because I open some other windows which need to appear and disappear from there), but how can I make those two items kind of static so they don't disappear?
I finally found an answer, in order for them to not be handled by the Windows menu you need to call
[timelineViewWindow setExcludedFromWindowsMenu:YES];
[mentionsViewWindow setExcludedFromWindowsMenu:YES];
and after that add the Menu items to the Windows menu and they will not disappear anymore.

How do I add items to the Finder context menu in Mac OS X?

I'm in the process of porting a Windows application to OS X (we wrote it in Java so most of the code is portable), but what I'm currently unsure of is how to add context menu items in the Finder window when the user right clicks on an item (i.e. I wish to add some items to the the menu that has "Open" "Open with" , "Get Info", etc... when the user right clicks).
Most of the articles I've found deal specifically with Windows (I've searched for "context menus" and "shell extension", but I believe I may be searching the wrong terms), so I'm curious as to how to go about adding this in Mac or what literature I should be reading.
You may want to take a look at using Services. The Finder appends applicable Services to the end of its contextual menu and, depending on your needs, just fit the bill.
In each Library folder may be a "Contextual Menu Items" folder. Special plugin bundles placed in that folder will be loaded and may place items in contextual menus. Look in Menus.h for the entry points of these plugin bundles.
CMPluginExamineContext
CMPluginHandleSelection
CMPluginPostMenuCleanup
From what I have read, Contextual Menu Items are not supported for 64 bit applications. As of 10.6 most Apple applications, including the Finder, run in 64 bit when available.
There are third party applications that restore contextual menu items on 10.6 if you must have them.

Resources