Exporting enviornment variables

Forum rules
Before you post please read how to get help
Level 1
Level 1
Posts: 44
Joined: Sun Feb 03, 2013 9:01 am

Exporting enviornment variables

Postby Stewbond » Tue Sep 24, 2013 3:36 pm

I have a script that I run to swap my xorg.conf from a 2-screen version to a 3-screen version. I'd like to export to an enviornment variable: NUMBER_OF_SCREENS.

Later, when I log-in, I run a script which randomly selects 2 images, resizes them, splices them togeather, and sets the wallpaper. I'd like to use NUMBER_OF_SCREENS to decide wether to splice a 3rd image in there.

PS. My second script is in Python, so if you know of a way to query the number of screens and the resolution of each screen, I'd be SOOOO happy.

Level 1
Level 1
Posts: 44
Joined: Sun Feb 03, 2013 9:01 am

Re: Exporting enviornment variables

Postby Stewbond » Wed Sep 25, 2013 2:23 am

Nevermind, I figured out how to do this in python without the need of enviornment variables.

I'm pretty proud of the script (first time in python), especially since online documentation seems to suck for these libraries. I use my Xinerama profile to figure out the number and resolution of each screen when splicing the images togeather.

Code: Select all

#!/usr/bin/env python
import os
import random
from PIL import Image
from Xlib import display
from Xlib.ext import xinerama

# Paths of source and target here
imgPath = "/home/stew/Pictures/Wallpapers/"
targetBackground = "/home/stew/temp/now.jpg"

# Here we get the screen information
screens = display.Display().xinerama_query_screens().screens

# Find the target width + height of the spliced image
targetwidth = 0
maxheight = 0
for scr in screens:
    targetwidth = targetwidth + scr.width
    if maxheight < scr.height:
        maxheight = scr.height

# Create our spliced image
imOut = Image.new("RGB", (targetwidth, maxheight), None)

# For each screen, get a random image, resize to fit the screen
# and paste into the spliced image
for scr in screens:
    imagePath = imgPath + random.choice( os.listdir(imgPath) )
    im = Image.open(imagePath)
    im = im.resize((scr.width, scr.height), Image.ANTIALIAS)
    imOut.paste( im, (scr.x, scr.y) )

# Save the image and set it as the background
os.system('gsettings set org.gnome.desktop.background picture-uri "file:///home/stew/temp/now.jpg"')

Return to “Scripts & Bash”