Is it possible to remove JAR files from the application list in Spotlight?

Solution 1:

I would like to do the same, but I think the answer is "it's not possible" or at least "it'd be risky to attempt".

Here's what I've discovered so far.

Associate JAR files to some other application?

I started by assuming Spotlight is inferring that JAR files are kind:application because JAR files are associated with Jar Launcher.app by default. Perhaps if we can remove that association then Spotlight will stop indexing JAR files as apps.

This can be done the standard way in Finder. View a JAR file in Finder, view info, select a different application under "Open With", click "Change All". I tried this and had no change in Spotlight results, however I didn't try rebuilding my Spotlight index.

I don't like this as I don't want Archive Utility associated with JAR files, nor do I have another application I'd rather associate. That led me to...

Remove association for JAR files with Jar Launcher?

This article purports to tell you how to remove a file association. It's only partly correct. It works to remove an association you previously added manually. Turns out it's no good for removing an association that comes from the system. I tried the referenced application, [RCDefaultApp][], which the article says can disable any association. Turns out the app just uses a kludge/workaround. It "disables" file associations by creating a new association to a dummy application, not by removing the actual association. This is no different than creating your own do-nothing application and associating it with .jar files.

  • RCDefaultApp Related, there's this answer to the question Where does Mac OS X Store File Associations. The highest rated answer is only partially correct. The defaults it references are your own "per user" additions or overrides of the system "default" defaults. Again, the most you could do would be to add an alternative association.

Where is Jar Launcher.app associated with JAR files?

A few of these articles reference the lsregister command-line utility (part of how to rebuild Launch Services' associations). Run this:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -dump

And you'll get a big dump of Launch Services' configurations. Including these relevant parts:

bundle  id:            48
    path:          /System/Library/CoreServices/CoreTypes.bundle
    name:          CoreTypes
    identifier:    com.apple.coretypes (0x800000ff)
    ...
    --------------------------------------------------------
    type    id:            2224
        uti:           com.sun.java-archive
        description:   Java archive
        flags:         exported  active  core  apple-internal  trusted  
        icon:          
        conforms to:   public.zip-archive, public.executable
        tags:          .jar, application/java-archive
...
--------------------------------------------------------------------------------
bundle  id:            21264
    path:          /System/Library/CoreServices/Jar Launcher.app
    name:          Jar Launcher
    ...
    library items:
    ...
    --------------------------------------------------------
    claim   id:            25284
        name:          Java JAR file
        rank:          Default
        roles:         Viewer  
        flags:         apple-default  apple-internal  relative-icon-path  
        icon:          Contents/Resources/JAR.icns
        bindings:      com.sun.java-archive, .jar

Which for me says a few things:

  • The Jar Launcher.app default association comes from /System/Library/CoreServices/Jar Launcher.app as opposed to some system wide plist file or similar. It may be possible to monkey around in there to break the association. I'd be concerned this could get undone with any Software Update which upgrades Jar Launcher
  • Independent of Jar Launcher, the bit above conforms to: public.zip-archive, public.executable leads me to believe I was wrong about Jar Launcher's association having anything to do with how Spotlight indexes JAR files. I interpret the output to mean "JAR files are a core type which are considered to be archives and applications"

I'm really uncomfortable mucking around with /System/Library/CoreServices/CoreTypes.bundle, but it would appear that's what is necessary to change the "Java archive" type, removing "public.executable" from "conforms to". I'd put my money that that's what Spotlight is using when indexing JAR files and treating them as kind:application.

As a Java developer, you know that not all JAR files are applications. A more sophisticated indexer could examine the manifest inside the JAR. But that would only fix Spotlight. Arguably it's an OS X bug that Finder treats all JAR files as applications, allowing you to Command-O them and attempting to run them via Jar Launcher. Without knowing more about Launch Services, that seems like a limitation of the file extension centric mechanism at work here. Bummer.

Solution 2:

Jar files often comes from reduced set of directories. In my case, most jar files was in "/Applications/Eclipse/plugins". So, in System Preferences > Spotlight > Privacy, I've just prevented Spotlight from searching into this particular location. Now, it works like a charm :)