Register
It is currently Wed Oct 22, 2014 11:54 pm

Auto Change Wallpaper At Login Script For Fedora 18 Spherica


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 

Too complicated? Badly written?
very good 0%  0%  [ 0 ]
good 0%  0%  [ 0 ]
not very good 0%  0%  [ 0 ]
Total votes : 0
Author Message
 PostPosted: Wed Jan 16, 2013 5:55 pm   

Joined: Wed Jan 16, 2013 5:40 pm
Posts: 4
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...
Code:
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.
Code:
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.

Code:
#!/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.


Top
 Profile  
 PostPosted: Thu Jan 17, 2013 3:54 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
hi,

uppercase variable names are for environment variables, not your own
/home/$USERNAME is $HOME, or ~
bin/ is not a place to store conf files, prefer etc/ (extension are pointless in Unix).
what if I don't have file ending with red? set nullglob shopt's option.
printf is useless
variable assignment should not contain spaces or it has to be inside quotes, or is it a command substitution ?

I won't test: I don't use gnome.


Top
 Profile  
 PostPosted: Fri Jan 18, 2013 6:19 am   

Joined: Wed Jan 16, 2013 5:40 pm
Posts: 4
right lower case is convention,
of course I should've used $HOME, how did i miss that :/
I put them in ~/bin because i noticed it echoed in $PATH by default so just thought it went there,
yeah Red is a requirement to filter them out,
nullglob shopt? I look forward to finding out what that is.
yeah its command substitution

thanx :)


Top
 Profile  
 PostPosted: Fri Jan 18, 2013 6:41 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
Quote:
yeah its command substitution
then it should happen inside $( )
Code:
$ var=$(command)
$ echo "$var"
command_output


Top
 Profile  
 PostPosted: Sat Jan 19, 2013 7:12 am   

Joined: Wed Jan 16, 2013 5:40 pm
Posts: 4
derrend wrote:
DISPLAY=:0 GSETTINGS_BACKEND=dconf

Can you tell me what this line does? they look like variables to me but if i list them as such with the other variables and not on the same line as the command as a whole it doesn't work correctly.


Top
 Profile  
 PostPosted: Sun Jan 20, 2013 5:33 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
I think I understand

I know DISPLAY is an X environment variable.
GSETTINGS_BACKEND is probably one for the gsettings command.

that's the reason why they have to be on the same line than gsettings.

I'm not so sure DISPLAY is useful, as X is already started.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP