Ubuntu – Force Mendeley Desktop GTK theme

14.04gtkmendeleythemes

I've been trying for a while to set the GTK theme of the Mendeley desktop UI, without success. The reason I want to do this is because I am using a dark theme, and that Mendeley is unreadable (dark font on dark bg) with this theme. The two relevant sources of information I'm using are here and here.

They both basically say that calling an executable like so

$ GTK_THEME=MyFancyTheme my_stubborn_app

should override the default GTK theme for the current user, and that permanent theme changes can be integrated in the .../share/my_stubborn_app.desktop by altering the EXEC line:

Exec=env GTK_THEME=MyFancyTheme /path/to/my_stubborn_app %u

None of these methods works in my case.
The special things about Mendeley desktop UI on Ubuntu (Trusty Tahr 14.04, Mendeley UI v1.14 in my case) are:

  • It comes as a standalone package with its own bin and share and lib folders and it uses Qt.
  • The actual binary is in lib/mendeleydesktop/libexec/mendeleydesktop.x86_64 (for Ubuntu 64 bits) but cannot be called directly because it requires environment variables defined by the python script bin/mendeleydesktop.
  • The mendeleydesktop.desktop file (which allows having an icon in the Unity launcher) is overwritten by bin/install-mendeley-link-handler.sh each time bin/mendeleydesktop is called.
  • This mendeleydesktop.desktop file is created/overwritten in $HOME/.local/share/applications.

What I did so far was to edit bin/install-mendeley-link-handler.sh so that the .desktop file overwritten at each call would include the modified Exec=env GTK_THEME... line. That doesn't seem to work. Can anyone help?

Best Answer

I finally managed to get it done, although it feels a bit clunky. In the following:

  • $MENDELEY_FOLDER is the Mendeley folder,
  • $CURRENT_GTK_THEME is the name of the GTK theme you are currently using
  • $MENDELEY_GTK_THEME is the name of the theme you'd like to use with Mendeley

NOTE: To get the name of the theme that you are currently using, type gsettings get org.gnome.desktop.interface gtk-theme in a terminal. A good theme to be using with Mendeley is Ambiance.

Create a new themes directory

We will essentially trick Mendeley into thinking that the root GTK themes folder is somewhere else.

mkdir $MENDELEY_FOLDER/share/themes/
ln -s  /usr/share/themes/$MENDELEY_GTK_THEME  $MENDELEY_FOLDER/share/themes/$CURRENT_GTK_THEME

Modify the script install-mendeley-link-handler.sh

It should be located in $MENDELEY_FOLDER/bin/install-mendeley-link-handler.sh. You need to edit the lines that overwrite the file mendeleydesktop.desktop, in my case:

cat > $DESKTOP_PATH/mendeleydesktop.desktop <<EOF
[Desktop Entry]
Name=Mendeley Desktop
GenericName=Research Paper Manager
Comment=Mendeley Desktop is software for managing and sharing research papers
Exec=env GTK_DATA_PREFIX=$MENDELEY_FOLDER $MENDELEYDESKTOP_BIN %u
Icon=mendeleydesktop
Terminal=false
Type=Application
Categories=Education;Literature;Qt;
X-SuSE-translate=false;
MimeType=x-scheme-handler/mendeley;application/pdf;text/x-bibtex;
X-Mendeley-Version=1
EOF

Notice the change in the Exec=... line.

Create a new mendeley executable

Wherever you keep your local binaries (eg $HOME/local/bin), create a new file mendeley with the following:

GTK_DATA_PREFIX=$MENDELEY_FOLDER \
    $MENDELEY_FOLDER/bin/mendeleydesktop

Then make it executable by running chmod +x mendeley, and run it in order to update the mendeleydesktop.desktop file.

If you installed Mendeley system-wide

The last step is only slightly different, in that the system-wide script (most likely located in /opt/mendeleydesktop) actually creates a link to the mendeleydesktop executable in $HOME/.local/share, and that is what the previous script needs to call instead.

Applying those changes to the Unity icon

The file to edit should be /usr/share/applications/mendeleydesktop.desktop. In this file, you should modify the Exec line as previously, by prefixing the call with the definition of GTK_DATA_PREFIX. This should do the trick :)