In Emacs no window mode, the background is automatically the same as the terminal (gnome-terminal). When I look at (frame-parameters) I see that (background-color . "unspecified-bg"). Well, for me, the background happens to be black. Is there a way to find out what the actual background color is for an Emacs session?

  • I don't think that the background color of a terminal emulator can be detected by an application inside of the terminal.
    – jordanm
    Mar 6, 2013 at 0:45
  • 1
    I do know this information can be found with gconftool...
    – Jeff
    Mar 6, 2013 at 15:02
  • @Jeff: And that is all you need to know! Mar 6, 2013 at 19:23

1 Answer 1


If you know how to find out from the terminal, you can use that selfsame command to find out from Emacs.

In my case, I'd make a script like this:


cat .Xresources | grep 'URxvt\*background\:' | cut -d" " -f2

(Note: -d is to set the field delimiter, -f is to set what field is to be shown: the first field is 1, not 0)

The command looks the way it does because .Xresources, the file that sets the background color, looks like this:

# ...
URxvt*background: black
# ...

Make the script executable (chmod +x), and put it in your PATH (echo $PATH).

If the script is called what_bg, in Emacs, M-x shell-command RET what_bg.

Edit (in response to comment):

See if this works. I tested it from Emacs, and in urxvt, xterm, and rxvt. While it is more portable than the first script, it assumes .Xresources configuration (which is, while not uncommon, obviously not everywhere).

I'm starting to wonder, though, why you need this to begin with?

And, if you indeed need it, can't you just look on the window to determine its color?

Anyway, the script:


terminal_emulator_parents=`pstree -As $$`
tep_list=`echo $terminal_emulator_parents | tr -s "-" | tr "-" " " \
          | tac -s' ' | tr '\n' ' '`

for process in `echo $tep_list`; do
    if [[ $process =~ ("urxvt"|"xterm"|"rxvt") ]]; then # here: add all
        found="true"                                    # terminal emulators
        break                                           # configurable
    fi                                                  # (and *configured*)
done                                                    # in ~/.Xresources

if [[ $found == "true" ]]; then
    echo -n "$process: "
    cat ~/.Xresources | grep -ie ^$process'\*background\:' \
                      | tr -s " " | cut -d" " -f2
    echo "Couldn't determine the terminal emulator."
  • I guess this is as close as I'll get for now. I was hoping to find something a little more cross-platform, but this is unix.stackexchange... shell-command is new to me so that's a good find.
    – Jeff
    Mar 8, 2013 at 17:10
  • 1
    @Jeff: Made an edit; take a look. Mar 9, 2013 at 10:11

You must log in to answer this question.

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