Here’s another micro-tip. I needed to decompile a Java class to step through for debugging. But I wanted to pick and choose classes from the Finder. No problem, this is macOS and Automator is your friend.

If you don’t already have it, download JAD (Java Decompiler) from http://www.varaneckas.com/jad.

Then open up Automator and create a new Service. Tell Automator that the service will receive only selected files or folders. You can use any application or just Finder, your call. If you like, filter out only the class files. Then comes the real work. Specify the zsh shell and give it this command line:

jad -lnc -o -d `dirname $1` $1

You’ll have to specify the full path to the jad executable if it’s not in your path. The -lnc tells JAD to add original line numbers as comments - very helpful when debugging. The -o tells JAD to overwrite output files without asking. And the -d tells JAD where to put the decompiled files. In our case we’re only allowing a single file at a time and we’re putting the decompiled file into the same directory as the original class file.

When you’re done, it should look something like this:

1

Save the workflow service and name it whatever you like, in my case I named it ‘Decompile Java Class’. Close any open Finder windows and re-open them. Now when you right click on a file you’ll see ‘Decompile Java Class’ as an option in the Services menu. Select it and JAD will decompile your selected class file into a .jad file.