Vladar's Blog

Custom file association in Linux

If you use TeXstudio1 like me, you might have used its session files to preserve the working state of the project you are currently developing. You can load, save, or restore a previous session through the File → Session menu.

The session files themselves are just text files that contain information about opened files and current editing options. While you can easily open them through TeXstudio, these files aren't associated with the application and when double-clicked, open in the default text editor instead (or at least that was the case for me).

Below I will describe the process by which you can create a proper association for an arbitrary file and change its icon accordingly.

📝 NOTE: This tutorial assumes Arch Linux2 distribution, but should probably work in a similar way on other ones as well.

Step 1: MIME file

Go to the following directory:

cd /usr/share/mime/packages/

And create a new file using your favorite text editor (here I use vim3):

sudo vim texstudio.xml

Write the contents of the file following this example:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-texstudio">
    <comment>TeXstudio session file</comment>
    <glob pattern="*.txss2"/>
    <icon name="texstudio"/>
  </mime-type>
</mime-info>

The contents are self-explanatory for the most part. You just need to update the following fields according to your needs:

  1. mime-typetype will be your custom type
  2. comment will describe the nature of the file
  3. globpattern will define the file pattern
  4. iconname (optional) will select which icon to use

📝 NOTE: If you forgot to open the file with sudo privileges, you can save the changes anyway, by typing the following command in vim: :w !sudo tee %4

Step 2: Desktop file

Go to the applications directory:

cd /usr/share/applications/

And check if texstudio desktop file is present:

ls texstudio*

If for some reason there isn't one, here's its contents:

[Desktop Entry]
Categories=Office;Publishing;Qt;X-SuSE-Core-Office;X-Mandriva-Office-Publishing;X-Misc;
Exec=texstudio %F
GenericName=LaTeX Editor
GenericName[de]=LaTeX Editor
GenericName[fr]=Editeur LaTeX
GenericName[ru]=Редактор LaTeX
Comment=LaTeX development environment
Comment[de]=LaTeX Entwicklungsumgebung
Comment[fr]=Environnement de développement LaTeX
Comment[ru]=Среда разработки LaTeX
Icon=texstudio
Keywords=LaTeX;TeX;editor;
MimeType=text/x-tex;
Name=TeXstudio
StartupNotify=false
Terminal=false
Type=Application

Now, run the following command to associate your new MIME type with the TeXstudio's desktop entry:

xdg-mime default texstudio.desktop application/x-texstudio

Step 3: Updating the MIME database

Finally, update the database to apply the changes:

sudo update-mime-database /usr/share/mime

If all goes well, you will now be able to open txss2 files in TeXstudio by double-clicking, and they will be represented by the application's icon in your file manager.


Discuss this post on Reddit


  1. https://www.texstudio.org/

  2. https://archlinux.org/

  3. https://www.vim.org/

  4. https://stackoverflow.com/a/7078429

#guide #latex #linux #software