Setting different default applications for different Desktop Environments
I've put together this solution to resolve your issue, and tested it on KDE and XFCE with opening text files and font files. It is a generic solution that should be applicable to any number of desktop environments and mime types. The way it works is there is a simple python script called custom-open that will open a file using different applications for different desktop environments. These are the steps to setup the solution:
- save custom-open script on your computer preferably on your path but doesn't have to be.
- save .custom-open.ini in your home directory ~/.custom-open.ini
- set custom-open as the default application for any file types you want handled by it.
custom-open
#!/usr/bin/env python
import traceback, sys, os, ConfigParser, os.path
from subprocess import Popen, check_output
from gtk import MessageDialog, MESSAGE_ERROR, BUTTONS_CLOSE
try:
file, desktop = sys.argv[1], os.environ['DESKTOP_SESSION']
mime = check_output(['file', '--mime-type', file]).strip().split(': ')[1]
config = ConfigParser.RawConfigParser()
config.read(os.path.expanduser('~/.custom-open.ini'))
cmd = config.get(desktop, mime)
Popen([cmd] + sys.argv[1:])
except:
msg = "CUSTOM OPEN ERROR\n\n" + traceback.format_exc()
MessageDialog(None, 0, MESSAGE_ERROR, BUTTONS_CLOSE, msg).run()
.custom-open.ini
[gnome]
text/plain = gedit
application/x-font-ttf = gnome-font-viewer
[xubuntu]
text/plain = leafpad
application/x-font-ttf = gnome-font-viewer
[kde-plasma]
text/plain = kate
application/x-font-ttf = kfontview
so what's great about this solution is that you can add as many new desktop environments as you want and as many mime type you want. to check what name you should provide for the desktop environment run the below command in a terminal.
env | grep -i DESKTOP_SESSION
to check the exact mime type of a file just run:
file --mime-type filename
EDITED: The need for symbolic links has been removed this should make it easier to use. I've also added a graphical error handler that will bring up an alert if an error occurs.
If you don't find the "right" way to do it, you could use a brute force method something like:
- Set all the defaults in one desktop environment
- Do something like an
cd $HOME;ls -Rlrt | less
to find out what files were just updated - i.e where those choices were saved - Make a separate copy of those files for each desktop environment (backed up).
- Repeat for each desktop environment
- Copy the appropriate set into place just before switching to that desktop environment (probably by logging out and logging back in and selecting the new desktop environment).
Hopefully, there's a way to switch desktop environments from a shell script with the option of telling the desktop environment where to get it's configuration files from. That might be cleaner than moving files around all the time, but I haven't researched if or how that works.
Another, much simpler solution, but not exactly what you asked for, would be to just:
- Create separate user accounts for each desktop environment
- Create a new group for these users
- Add all these users to the new group
-
Make any common data files you need to access from all these users
-rwxrwxr-x
(chmod 775 list-of-files-and-directories
). That way you won't get permission errors trying to write to a file that another one of your "users" wrote to first.- If you want some files to be the same across all these users, you can create them in one user and symlink them to the rest of them. This should work, but will require you to remember they're set up that way when you change any of them. For instance, if you edit one of them and your editor makes a backup file, that backup file will only be saved where you edited it, not on all the other user accounts.