Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Use Automator to extract JAR files in the Finder System 10.4
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.
    •    
  • Currently 2.67 / 5
  You rated: 5 / 5 (6 votes cast)
 
[31,067 views]  

10.4: Use Automator to extract JAR files in the Finder | 13 comments | Create New Account
Click here to return to the '10.4: Use Automator to extract JAR files in the Finder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Use Automator to extract JAR files in the Finder
Authored by: Arlo on Sep 20, '05 10:22:00AM
I feel compelled, yet again, to let Automator users know you do not need the "Get Selected Finder Items" action for a Finder plug-in.

---
www.automatorworld.com
"Better Living Through Macintosh Scripting"

[ Reply to This | # ]

10.4: Use Automator to extract JAR files in the Finder
Authored by: gamov on Sep 20, '05 12:41:54PM

it doesn't work for me.
It fails at the mkdir command or doesn't seem to do anything :o(



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: vocaro on Sep 21, '05 04:26:39PM

Can you provide more detail about what goes wrong? Maybe I can help.



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: didde2 on Sep 20, '05 01:10:55PM

This seems like an overkill to me. You do know that a simple rename works too, right? Rename whatever.jar to whatever.zip and just double-click. Voila, Bob's your uncle.

JAR == ZIP-compression in other words.



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: Anonymous on Sep 21, '05 10:01:40AM

Heck, I'd even call this overkill!

If this is a hint for developers, what developer doesn't have a Terminal window open at any time?

I've got the phrase "jar tvf ..." builtin to my muscle memory.



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: vocaro on Sep 21, '05 04:24:35PM

If this is a hint for developers, what developer doesn't have a Terminal window open at any time? I've got the phrase "jar tvf ..." builtin to my muscle memory.

As do I. There are a million things you can do from the Terminal, but doing those things from the GUI can be easier and faster.

After all, it's not as simple as you imply. You must first switch to the Terminal, find or open a window so that you have a ready command prompt, switch to the directory containing the JAR, make a directory to hold the extracted files, type "jar xf ../" followed by the name of the JAR, and then switch back to the original directory (so that you don't lose your old context).

The Finder plug-in described in this hint does all those things for you in one step, so you never even have to touch the keyboard. I don't think it's overkill at all.



[ Reply to This | # ]
Terminal savvy
Authored by: sjk on Sep 21, '05 09:12:48PM

But it's also not necessarily as complicated as you imply. :-)



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: vocaro on Sep 21, '05 04:13:59PM

You do know that a simple rename works too, right? Rename whatever.jar to whatever.zip and just double-click. Voila, Bob's your uncle.

I forgot about that, but I still prefer the Finder plug-in. Renaming the JAR can cause serious problems by preventing Java from finding that JAR. If you want to run the program, you'll have to rename it back to a JAR once again -- yet another step.

In any case, calling it "overkill" is a matter of preference. Selecting a menu item is more convenient for me than renaming the file, since you never have to type a key in order to examine the JAR's structure or open its files.



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: Anonymous on Sep 20, '05 08:42:49PM

All seems a bit of a hassle to me. I've just set BOMArchiveHelper (which is the Finder .zip helper application in /System/Library/CoreServices) to be the helper app for .jar, .ear and .war files. To do this, Get Info on a file of each type and change the helper app in the Open With section. Don't forget to click the Change All.. button to apply this to all files of the same type.

Once you've done this, you can simply double click a .jar, .ear or .war file in the Finder and it will be unzipped for you.



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: gamov on Sep 20, '05 11:05:08PM

that's a good idea to use the BOMArchiver BUT you shouldn't change the Default type since applications stored in jar can be launched by double-clicking on it and it should stay the standard behavior.
Now, remain to find a way for the finder to propose the BOM archiver directly on the menu instead of having to go through the painful Open dialog



[ Reply to This | # ]
10.4: Use Automator to extract JAR files in the Finder
Authored by: Anonymous on Sep 21, '05 06:47:58AM

Fair enough but I have so few .jars I want to launch via the Jar Launcher, I prefer to custom open those (drag onto Jar Launcher) on the very few occasions I need to. As a J2EE developer I spend most of my time unzipping .jars, not running them in the GUI. I suspect there are a lot of people in the same position.



[ Reply to This | # ]
BOMArchiveHelper
Authored by: sjk on Sep 21, '05 09:22:24PM

On my 10.3.9 system, opening a .jar file with BOMArchiveHelper created a .cpgz archive of it rather than extracting it. If it does indeed extract files on 10.4, you could drag BOMArchiveHelper to the Dock then drop .jar files on its icon.



[ Reply to This | # ]
BOMArchiveHelper
Authored by: junk666 on Dec 19, '09 04:37:47AM

Just get something, anything for expansion besides bomarchivehelper. It cannot be launched except by double-clicking or option-clicking an archive, and it has no preference file to change the way it works. It doesn't create a folder with the same name as the original archive, but throws the file out with no folder. That means if the original archive were "Annies_file.zip", but the file inside is called "Zider_Zea_trip.jpg", it will go to the end of the alphabet instead of staying with the archive. That's very irritating. I know people are strange to zip a single file, but it adds security in transit, so I can see why they would do it. Use ZipEg or anything but bomarchivehelper. Other utilities will retain the naming method so you don't have to go looking all over the place for the expanded file.



[ Reply to This | # ]