Definitely Important and Not a Waste of 10 Minutes

So…Xfce has this nifty app Terminal that lets you set a background. Naturally, leaving the background black would be too easy. I wanted a picture. But what’s more, I wanted that picture to change…

So I found that the Xfce Terminal app has a pretty simple config file in ~/.config/Terminal/terminalrc. After that, parsing it and changing the background picture in Python was easy:

#!/usr/bin/env python
import os
import sys
import random

photo_exts = ['png', 'jpg']
user_dir = os.getcwd()
photo_dir = '%s/Pictures/' % user_dir
config_path = '%s/.config/Terminal/terminalrc' % user_dir
with open(config_path, 'r') as f:
    opts_list = f.readlines()
opts_dict = {}
for line in opts_list:
    if '=' in line:
        opts_dict[line.split('=')[0]] = line.split('=')[1].strip('\n')
    elif 'Configuration' not in line:
        opts_dict[line.strip('\n')] = ''
photo_list = []
for (path, dirs, files) in os.walk(photo_dir):
    for file_name in files:
        ext_pos = len(file_name) - 3
        if file_name[ext_pos:] in photo_exts:
	    photo_list.append('%s/%s' % (path, file_name))
opts_dict['BackgroundImageFile'] = random.choice(photo_list)
opts_list = '[Configuration]\n'
for (index, item) in opts_dict.iteritems():
    if item:
        opts_list += '%s=%s\n' % (index, item)
        opts_list += '%s\n' % index
with open(config_path, 'w') as f:

Next, we add comments and maybe some clever one-liners for the array generation…