views:

602

answers:

3

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!

A: 

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

Joshua Nozzi
i don't understand your answer fully: why you mean "leave the world of cocoa" and then post an xcode piece?
z3cko
SampleCMPlugin uses Carbon, not Cocoa. There is no Cocoa way to do this. As to "post an xcode piece", I don't know what you mean. If you mean sample code, I already did. Short of handing you a completed plugin, this is a full and complete example.
Joshua Nozzi
The SampleCMPlugIn sample doesn't work in Snow Leopard.
geowar
A: 

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.

ExitToShell
do you have an example for a drag-and-drop applescript application that works on Leopard and Snow Leopard?
z3cko
+3  A: 

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.

Chris Hanson
this is a very good approach! thanks for the answer! can you tell me more about the Services in Leopard and SL? So that means I can create Services on Leopard that would also work on Snow Leopard?
z3cko
You should be able to create Services on Leopard that also work on Snow Leopard but don't take advantage of all of the new Services features. Just look at the Mac OS X Dev Center, especially the AppKit release notes, for details on creating Services.
Chris Hanson