Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I heard about a script which will change the colors of GNOME Terminal each time it starts. I can't remember where I saw this...

share|improve this question
    
You want different, random colors each time? –  innaM Sep 16 '09 at 6:35
    
Well not random. It was more like predefined. –  Lucas McCoy Sep 16 '09 at 19:19
add comment

1 Answer

up vote 1 down vote accepted

I haven't seen the script you mention. But I think it is possible to create such a script.

Gnome Terminal picks up the background colour from the profile in use, so any change will impact the background colour of all terminals using the same profile.

That said, the configuration key is stored in */apps/gnome-terminal/profiles/Default/background_color*, where Default is the currently used profile.

It can be set thus:

gconftool-2 --set "/apps/gnome-terminal/profiles/Default/background_color" --type string "#E376DDDDFFFF"

So, I'm guessing that one can write a script to clone the Default profile on the fly, change it's *background_color*, invoke gnome-terminal with this profile, and delete the profile before exiting. You'll also need a database of good foreground/background color combinations for this script to use.


Update: Here is a script to do what is discussed above. It does not generate a random background color, that you'll have to generate using some list.

#!/bin/bash 

PROFILE_NAME=${RANDOM}_p_${RANDOM}
TMP_DIR=/tmp
DEFAULT_PROFILE=Default
PROFILE_EXPORT_FILE=${TMP_DIR}/${PROFILE_NAME}.xml

#replace with program to generate a random background color
BACKGROUND_COLOR="#0000AA000"

# dump the "Default" profile, replace with new random profile name
gconftool-2 --dump /apps/gnome-terminal/profiles/${DEFAULT_PROFILE} > ${PROFILE_EXPORT_FILE}
sed -i "s/${DEFAULT_PROFILE}/${PROFILE_NAME}/g" ${PROFILE_EXPORT_FILE}

# load the new random profile, change the background color
gconftool-2 --load ${PROFILE_EXPORT_FILE}
gconftool-2 --set "/apps/gnome-terminal/profiles/${PROFILE_NAME}/background_color" --type string "${BACKGROUND_COLOR}"

# add the new random profile to list of profiles
PROFILE_LIST=`gconftool-2 --get /apps/gnome-terminal/global/profile_list`
NEW_PROFILE_LIST=`echo $PROFILE_LIST | sed "s/]/,${PROFILE_NAME}]/g"`
gconftool-2 --set  /apps/gnome-terminal/global/profile_list --type list --list-type string "$NEW_PROFILE_LIST"
# start gnome-terminal with new random profile, such that the script blocks till terminal is closed.
gnome-terminal --window-with-profile=${PROFILE_NAME} --disable-factory

# cleanup: remove the new random profile, and remove it from list of profiles
gconftool-2 --recursive-unset /apps/gnome-terminal/profiles/${PROFILE_NAME}
PROFILE_LIST=`gconftool-2 --all-dirs /apps/gnome-terminal/profiles | sed "s/ \/apps\/gnome-terminal\/profiles\///" | sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}'`
gconftool-2 --set  /apps/gnome-terminal/global/profile_list --type list --list-type string '['"${PROFILE_LIST}"']'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.