I have to work with a script that forks and launches an instance of xterm in order to display log output in one window and have an interactive interface in the other. Personally I prefer rxvt-unicode and I would like to modify this script so that it is no longer hardcoded to use xterm.

Is it possible to either figure out the users preferred terminal in a desktop-agnostic way or to get the parent terminal. The parent terminal might not be the next parent in the process tree since it's possible that the script in question can in term be called by another script or application.

Since the script is written in Perl a solution written in Perl is good enough as long as it doesn't have weird dependencies (I can't control the global environment).

  • 2
    I would suggest running the process inside a screen/tmux session, then open up a terminal window, running screen/tmux attached to the same session in read-only mode. No example, so not posting as an answer.
    – gertvdijk
    Dec 20, 2012 at 13:41
  • 1
    For finding the 'default' terminal in the environment I suggest to read the /etc/alternatives/x-terminal-emulator link (if available on the platform).
    – gertvdijk
    Dec 20, 2012 at 13:44
  • @gertvdijk that's what I would do. Problem is, most users don't know how to use screen/tmux and I don't want to modify the default behaviour. The /etc/alternatives/x-terminal-emulator link does not exist I'm afraid. Still, I want the script to use urxvt in my case which it definitely wouldn't point to. In the general case this would be much nicer than a hardcoded xterm though.
    – David Holm
    Dec 20, 2012 at 13:57
  • See also How to launch an application with default "terminal emulator" on Ubuntu? but that's specific to Debian and derivatives, and it gives the system default, not the user's favorite. Dec 21, 2012 at 1:03

2 Answers 2


Freedesktop specifies standard ways of opening files with the user's favorite program (the xdg-open command), of launching a screensaver (xdg-screensaver), and more. Unfortunately for you, an xdg-terminal has been proposed and you can find a third-party implementation but it is not widely available.

You could do worse than reusing the Chromium xdg-terminal script. It tries to detect the user's desktop environment, falling back to $TERM, falling back to xterm.


I'm not sure there is a desktop-agnostic way to find preferred terminal, but you might want to search at freedesktop.org. For example xdg-utils look a bit like what you are looking for, although exactly terminal is slightly different from the "use application A to open B" approach the Portland project seems to be taking.

  • xdg-utils don't seem to be deployed on our systems. :/
    – David Holm
    Dec 20, 2012 at 16:06
  • @DavidHolm well you can check how they do it and either request it added to the environment or reimplement in Perl - I wouldn't expect it to be that complicated.
    – peterph
    Dec 20, 2012 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .