PDA

View Full Version : <SOLVED> Auto Change Wallpaper At Login Script For Fedora 18 Spherical-Cow



derrend
17th January 2013, 02:36 AM
I had a script that did this for me on fedora 17 but I had to modify it for fedora 18 so I thought I'd post it for anyone who might want it.

What you need:
A folder called 'wallpaper' inside of your 'Pictures' folder that contains the wallpapers you wish to use.
A folder called 'bin' inside your users 'home' folder containing this script.
You need to change the owner of the default login background file '/usr/share/backgrounds/spherical-cow/default/wide/spherical-cow.png' to you with the command below...

sudo chown YOURUSER:YOURUSER /usr/share/backgrounds/spherical-cow/default/wide/spherical-cow.png
Set this script to run with your startup programs. You can invoke the GUI menu by entering the command below into your terminal.

gnome-session-properties
You need to convert your chosen pictures into '.png' format using GIMP and also make a black and white copy of each one. Your files should have identical names except the ones in colour should have 'RED.png' at the end and the ones not in colour should have 'BLACK.png' at the end.

What it will do:
Pay attention It will pick a colour picture at random from your folder, save it and set the corresponding black and white file as the login screen background. Then, the next time you restart your computer it will display the black and white version of your picture at login and fade nicely into the colour version once you enter your password.


#!/bin/bash

#1 The 3 variables below set the paths and locations to and of your files.
WALLPAPERDIR=/home/$USERNAME/Pictures/wallpaper
BNWWALLPAPER=/usr/share/backgrounds/spherical-cow/default/wide/spherical-cow.png
PREVPIC=/home/$USERNAME/bin/prevpic.txt

#2 This one lists all the colour files (ending in RED) in the background.
FILES=($WALLPAPERDIR/*RED*)
#3 This one chooses a file at random from the backgroung list.
RANDOMPIC=`printf "%s\n" "${FILES[RANDOM % ${#FILES[@]}]}"`

#4 This shortens the length of the path to your colour picture to 37 characters, you will need to change this, it should stop 3 or 4 characters after entering your wallpaper folder, in other words it should only show the first few letters of a file name in your wallpaper folder.
FILESTART=`echo $RANDOMPIC | cut -c 1-37`
#5 Uncomment the code below to show you the length of FILESTART when you run this script in a terminal.
#echo $FILESTART
#6 This sets the variable BNWFILE (directly below) as the absolute path to the corresponding blank and white file (ending in BLACK) of the randomly chosen colour file a few lines above.
BNWFILE=`echo $FILESTART*BLACK*`

#7 This command sets the background wallpaper after login - notice that it gets in input from the variable PREVPIC up at the top.
DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri file:"`cat $PREVPIC`"
#8 This copies the file at the end of the absolute path contained in BNWFILE to the location of the default wallpaper represented by BNWWALLPAPER
cp "$BNWFILE" $BNWWALLPAPER
#9 The absolute path of your randomly chosen colour picture (located in RANDOMPIC) is placed into the file represented by PREVPIC.
echo "$RANDOMPIC" > $PREVPIC

exit 0

Why did I make it this way?:
The script doesn't run until you have logged in so what it is actually doing is showing you the black and white login screen that was chosen the last time you were using your computer, then as you're logging in it reads the name of the colour picture in the file and sets it which is why it looks fluid but in reality is not. Meanwhile the black and white picture has been replaced with a new one (ready for the next time you log in) and the name of colour picture linked with it was written to the $PREVPIC file (also ready for the next time you log in).

I wanted to impact the system as little as possible which is why all the permissions are user permissions and not root. Also I didn't want to change the default system architecture at all, even the default login wallpaper file name remains unchanged, the only footprint is the default owner of the file being changed but that is all.

Improvements??
I know this isn't the cleanest script in the world, if someone has a way to simplify it further or improve it then feel free to post your suggestion, a modified version of the script or indeed your own script.

---------- Post added 17th January 2013 at 01:36 AM ---------- Previous post was 16th January 2013 at 11:08 PM ----------

think i may have posted this in the wrong forum :/

bob
17th January 2013, 02:41 AM
I've moved this to Guides and deleted the other thread that you'd posted there. Almost lost both of them due to multiple Admin efforts to straighten out the mess. Frankly, if you've made an error, simply ask one of us to fix it, but don't post a second one, as it's against Forum rules.

DBelton
17th January 2013, 02:43 AM
Ya.. I had one of those WTF??? moments :lol:

Good thing I did a "soft" delete :D

bob
17th January 2013, 02:51 AM
Yeah, Dan, I'd hard-deleted the other one. OOPS! :blink: Thankfully, I could still rehab yours.

derrend
18th January 2013, 01:06 PM
disaster! :)

DBelton
18th January 2013, 05:32 PM
You know, I believe that the ~/bin folder is getting to be one of the best kept secrets. That is one of the very first things I create when I do a new install and put my scripts into it. (I actually create 2, one in my user's home and one in root's home)

That way, running my scripts is simple. ~/bin is already in the default path :)