Exporting enviornment variables

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Stewbond

Exporting enviornment variables

Post by Stewbond »

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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Stewbond

Re: Exporting enviornment variables

Post by Stewbond »

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
imOut.save(targetBackground)
os.system('gsettings set org.gnome.desktop.background picture-uri "file:///home/stew/temp/now.jpg"')
Locked

Return to “Scripts & Bash”