Contextual Menu Item development for OSX (Leopard and Snow Leopard) - cocoa

i was wondering what the best practice is for creating a contextual menu item that would work in both leopard and snow leopard and works with a selection of files and/or folders, sending them to a shellscript.
i know that the contextual menu items have been deprecated in SL - but does that mean there is no way to create a solution that would work on both Leopard and Snow Leopard (using applescript or xcode or automator)?
basically i want to feed the files/folders to a shellscript that creates different compressed archives (rar, zip, tbz2) out of them.
thanks for your help!

There's not really a way to create one overall piece of code that will work in both Leopard and Snow Leopard.
You can, however, create a service for Snow Leopard and then create a Finder contextual menu for Leopard that just invokes that service.
That way you can do most of your implementation in Cocoa as part of the service, and only use the Finder contextual menu portion on systems that can't "natively" use the service.

Short of using an Automator service (10.4 or above) or the newly-overhauled services system (10.6 only), you'll have to leave the comfortable world of Cocoa:
SampleCMPlugIn

You can make an AppleScript application that accepts a drag 'n' dropped file/folder onto it.
You can probably make an Automator app to accept drag 'n' dropped files also.
Both should work on Leopard and Snow Leopard. On Snow Leopard, at least, you can set up a new Services Menu item that points to a particular app to process the selection. This is done via the Keyboard preference panel.

Related

Create custom right-click menu for OS X app, developed on Linux

I am creating an app for Mac OS, but it is being built on Linux. Because of this, I am not able to use tools such as Xcode, and I am not developing in swift. Rather, the .app directory is being put together according to Apple's documentation, and the entrypoint/executable of my app is a shell script.
I need to customize the menu which appears when you right click on the app (either on the dock icon or in Finder). Is there a way to do this, without using cocoa, etc.?
The menu I believe you are referring to is called "Services".
In order to add a menu item there for your application you would create a script to enable including it there. Xcode isn't needed or required, however, you'll need to know at the very least some basic AppleScript or Javascript to accomplish what you want. (see examples from the link)
↳ Mac Automation Scripting Guide

RCP application menus in Mac OS

I am struggling to figure out how RCP applications on Mac OS work with "About" and "Preferences" actions. I create them with ActionFactory and place them to relevant file menus. Works fine everywhere. However, on Mac OS those actions get placed into application menu by something which knows better where to put other peoples good actions. But of course they don't work.. Any idea why?
(eclipse target platform 3.7, OSX - the latest El Capitan)
For the 3.x style action bar advisor add the menu item in the normal place but use an ActionContributionItem and set the menu item in be invisible on the Mac:
So for Quit something like:
IWorkbenchAction quitAction = ActionFactory.QUIT.create(window);
register(quitAction);
ActionContributionItem quitItem = new ActionContributionItem(quitAction);
quitItem.setVisible(!Util.isMac());
menu.add(quitItem);
'About' and 'Preferences' can also be specified like this.
Util is org.eclipse.jface.util.Util.
Eclipse will find these items and move them to the correct place.

how to add item in right click context menu of file and folder in objective c

I am developing an cocoa application for Mac and what i need is to add an item in the context menu that appears when user right-clicks on specific file and folder (i.e. when user click on file or folder by pressing ctrl key of keyboard).
I am new to Cocoa application development. I have searched in google for it and found that it can be implemented by using CFPlugIn. Does anyone know how to use CFPlugIn to implement this or any other method to add item in context menu of specific file or folder??
Thanks in advance
You can use system services for contextual menu. you should refer Services Implementation Guide. take a look at Services step out in Snow Leopard article.
If you wish to sell your product on apple app store than you should not follow dropbox.
This is no longer supported in Mac OS X 10.6 and Mac OS X 10.7. Earlier versions of Mac OS X had support for contextual menu plugins, but this feature has since been removed.
What is it you're trying to accomplish in the broader sense? If you give us an idea of what your goal is, we may be able to suggest an alternate way to accomplish it.
Using System Extensions and a FinderSync extension you can accomplish this.
https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/Finder.html

NSWindow not Activating

I create a window in a helper tool that runs in the background (it's not an app bundle with a .nib and Info.plist, but a plain executable). When -makeKeyAndOrderFront: is called, the window is displayed but it does not "pop" out like an active window.
Can this be fixed?
Regards,
Erik
You should wrap the helper tool as a regular .app bundle with at least Info.plist. Then the problem goes away. A GUI app in OS X needs to have an Info.plist to receive events correctly.
The way a GUI app misbehaved if not in an app bundle has never been clear to me. If I remember correctly, it changed over time, depending on OS X's versions. I think it behaved worse in previous versions of OS X. For example, the window is shown but I couldn't click any UI inside it.
Many people who compiled a program in a cross-platform toolkit faced this problem, see e.g. this discussion here in the WxWidgets wiki. Apparently, OS X doesn't mark a program not within an .app bundle as a foreground-able app, which causes your problem. You can use TransformProcessType from your binary not inside an .app bundle to make a foreground-able app to solve your problem, but that's not a documented/intended usage of this function.
So, just wrap it in an .app bundle.
Update:
This "foreground-able-ness" is controlled by the activationPolicy of an app, see this doc on NSApplication. Found the info on this post on Cocoa with love.

Mac OS X Services: enable without user interaction?

I wrote a simple Mac 'Service' for Finder, that executes a command.
Basically: this adds a ContextMenu in Finder.
If I right-click a file in Finder, a menu item pops up. If the user clicks it, it executes my script. (kind of like 'Send to Bluetooth device, ...')
In OS X Leopard (10.5) and earlier, all services are enabled.
In 10.6 (Snow Leopard), Apple changed the behavior, services now have preferences, and can be enabled or disabled by the user. (which is a good thing)
However, I wrote the service, but there seems to be no way to enable it automatically (in our installer).
I tried doing it with Applescript, going to the System Preferences and ticking the checkbox that way, but it requires some accessibility features to be turned on. (off by default).
Is it possible? If so, how?
Or do I need something else to provide Context Menus in Finder.
I tracked File changes on my filesystem while changing the preferences and discovered there was a plist file:
~/Library/Prefrences/pbs.plist
which contains what I need.
If I edit that manually, it seems to work. So, problem solved :)

Resources