.mht Files Showing Exec Icon on Mac – How to Fix

filefirefoxmacos

I am working on a Mac (Yosemite, OS X 10.10.5) and I have several mht files which I created on Firefox by selecting File → Save as MHT. I have already associated the files with Firefox — it opens them by default — but the files continue to show the exec icon. What I am looking for is a way to make macOS recognize the mht file extension: for eg, when a PDF file is renamed in macOS, only the name of the file is highlighted but not the extension, however when a mht file is renamed, both the name of the file and the file extension (mht) are hightlighed.

I tried browsing to Firefox -> Show Package Contents -> Contents and, since it was missing, I added mht to the Info.plist using TextEdit:

<dict>
    <key>CFBundleTypeExtensions</key>
    <array>
        <string>html</string>
        <string>htm</string>
        <string>shtml</string>
        <string>xht</string>
        <string>xhtml</string>
        <string>mht</string> <!-- added -->
    </array>
    <key>CFBundleTypeIconFile</key>
    <string>document.icns</string>
    <key>CFBundleTypeName</key>
    <string>HTML Document</string>
    <key>CFBundleTypeOSTypes</key>
    <array>
        <string>HTML</string>
    </array>
    <key>CFBundleTypeRole</key>
    <string>Viewer</string>
</dict>

This did not work. Is there any way to make macOS recognize the mht extension and associate it to the Firefox icon? Alternatively, how can I make macOS associate an icon to these files (other than manually changing the icon on each file in the Get Info window)?

Best Answer

In the comments, you indicated that the problem files were on an external drive. Is it formatted as FAT (or NTFS)?

These filesystems have no concept of executable files, so the system seems to assume that everything is an executable program. Don't worry, there's nothing wrong with the file.


Why does it do this? Well, it's a permissions problem.

To see the permissions on a file, you can open a terminal, type ls -ld with a space after it, drag in your file, and press Return. The first part of the output will look like this:

-rw-r--r--

So what does all this mean?

r: read  w: write  x: execute

    -        rwx     rwx     rwx
    |       └─┬─┘   └─┬─┘   └─┬─┘
additional  user    group   world
  info     perm.s   perm.s  perm.s

Try this on some file in your home folder. You should get something like rw-r--r--. Now try something on your external drive—it's probably rwxrwxrwx.

(External drives usually don't have a concept of ownership, so even on an HFS+-formatted drive you'll get the same set in each field. Edit: I tested this on a random file and it came back with rw-r--r--. Oops.)


Fixing the problem

The proper way

If the partition the file is on is formatted HFS+ (like your system disk) or any Unix filesystem (e.g. ext4, XFS), then you can use chmod. To do this, type chmod -x into a terminal, add a space, and drag in your file, just as with ls above. Hit Return, and you should be golden.

In fact, this is always worth a shot—it's safe to try on any type of filesystem. If it doesn't work, see below.

The improper way—just hiding it

On filesystems with no concept of executable files, chmod will silently fail and nothing will happen. You can still hide this by setting an icon. To do this, Get Info on a file (⌘I) and drag a .icns file onto the icon in the top left corner. (You can also just copy and paste the icon from something else—that's probably the way to go here. If you want a custom icon, read on.)

So, how do you get this mysterious .icns file?

The easiest way is simply to open an image in Preview, select everything (⌘A), and copy it (⌘C). Then you can just paste it into the corner icon (click to select it first).

But .icns images have a hidden benefit—they can display differently at different sizes. This is great for app icons, which is their main reason for existence. If you want to make your own image do this, you can do the following:


Slightly off-topic: making your own icon images behave differently at different sizes

  1. Collect a set of images, with sizes of 64x64 up to 1024x1024. These are for Retina displays, you'll downsize them later. Put them in a folder named whatever.iconset.
  2. Rename each of them to icon_<halfwidth>x<halfheight>@2x.png (for example, the 64px icon would be icon_32x32@2x.png).
  3. Duplicate each icon, halve its size, and rename it icon_<newwidth>x<newheight>.png (for example, icon_32x32.png). This can be automated with a shell script, using the sips command (run man sips for more info on using it).

You'll see that if you Quick Look preview the folder, you'll see your icon, and see how it behaves at different sizes.

  1. Convert it to a .icns with this command: iconutil --convert icns and drag in your iconset, as with the other commands.

Associating the file type with Firefox

I don't know whether your process would have worked, but you'll need to make sure the system can see the change. You do this with lsregister:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister .../Firefox.app

Replace .../Firefox.app with the path to Firefox, or drag it into the terminal.