10.4: Use Automator to extract JAR files in the Finder

Sep 20, '05 09:49:00AM

Contributed by: vocaro

Tiger only hintWhen I first heard about Automator, it sounded wonderful, but when I got a chance to actually use it, it was a bit of a let-down. Automator was just too simple and limited for my needs. Every time I tried to create a workflow, I felt like I was experiencing the programmer's equivalent of riding around in a bumper car.

But thanks to various Mac OS X Hints, such as this one, I've learned that Automator is actually very well suited for extending the Finder with new capabilities. For example, Java developers like myself often need to extract the contents of a JAR file. Here's how to use Automator to create a Finder plug-in that does just that:

  1. Launch Automator, select the Finder Library entry, and then drag the Get Selected Finder Items Action to the work area.

  2. Select the Automator library and drag the Run Shell Script Action to the work area.

  3. Change the Pass Input value to as arguments.

  4. Set the script text to the following:
      cd `dirname "$1"`
      mkdir `basename "$1" .jar`
      cd `basename "$1" .jar`
      jar xf "$1"
    
  5. Save the workflow to the ~/Library -> Workflows -> Applications -> Finder directory (i.e. use File: Save As and make sure Finder is set as the type in the pop-up) as "Extract JAR File."
You will now be able to right-click (control-click if you're a single-button mouser) a JAR file in the Finder and select Automator > Extract JAR File to extract it.

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050916045108565