You are not logged in.
I made a simple script for random wallpapers
#!/bin/bash
Dir="/media/Data/Images/wallpapers"
if [ ! -d "$Dir" ]; then
echo "Not Exist $Dir"
exit 1
fi
SetBG () {
TotalFiles=$( ls -1 "$Dir" | wc -l )
RandomNumber=$(( $RANDOM % $TotalFiles ))
test ! $RandomNumber = 0 || RandomNumber=1
RandomFile="$( ls -1 $Dir | head -n $RandomNumber | tail -n 1)"
#echo "Selected File: $RandomFile"
feh --bg-fill "${Dir%/}/${RandomFile}"
}
while true; do
SetBG
sleep 20m
doneLast edited by SuNjACk (2011-02-19 21:39:03)
"I'd rather run Linux on a 6.5KHz machine through an ARM emulator than run Vista"
Offline
Hello,
i'm a beginner. Can you tell me the name of file extension ?
thanks for this one,
Offline
You can use sh as the file extension but it will also work fine without it.
Note: ** Please read before posting **
BTW if you wish to contact me, send me an e-mail instead of a PM.
Offline
hello fouck,
you only have to make the file you save the text to "executable". you can do it in the filemanager if you select the information/properties window of the file or you can use the terminal. In the terminal you have to type
cd the/folder/where/the/script/is
chmod +x script_nameobviously replace the names accordingly in the above. "cd" means "change directory" and will just do that (like clicking in a filemanager) and "chmod" means "change mode" and "+x" means "make this file executable" (or "add the right to execute this")
have fun.
@sunjack
my .zshrc (I don't use bash) ...
(from here)
so it seems this does not hold for scripts 
you could put some quotes around the dir and file names just in case you ever drop a file with a space in there.
Offline
hello fouck,
@sunjackSuNjACk wrote:my .zshrc (I don't use bash) ...
(from here)
so it seems this does not hold for scripts
you could put some quotes around the dir and file names just in case you ever drop a file with a space in there.
thanks for the suggestions, I updated the script
"I'd rather run Linux on a 6.5KHz machine through an ARM emulator than run Vista"
Offline
there was an error when running ur script please help:
./script: line 18:feh :command not found
Offline
ervichu, have you thought about installing the missing package?
if not (and you want to) then
sudo aptitude install fehOffline
or you could do it without feh using corenominals favorite wallpaper manager (?)
just replace
feh --bg-fill "${Dir%/}/${RandomFile}"with
nitrogen --set-auto "$Dir"/"$RandomFile"Last edited by ali (2011-06-09 05:31:21)
Offline
Offline
Does this script check folders recursively, like folders within the designated folder? Also, do I need to run this script every time I boot the computer?
the original doesn't seam to check recursively, i modified it a little so it does what you asked for (i hope he doesn't mind)
#!/bin/bash
Dir="/home/ali/.backgrounds/"
if [ ! -d "$Dir" ]; then
echo "Not Exist $Dir"
exit 1
fi
SetBG () {
while IFS= read -rd '' file; do list+=("$file"); done < <(find "$Dir" ! -type d -print0)
TotalFiles=${#list[@]}
RandomNumber=$(( $RANDOM % $TotalFiles ))
test ! $RandomNumber = 0 || RandomNumber=1
RandomFile="${list[RandomNumber]}"
#echo "Selected File: $RandomFile"
feh --bg-fill "${RandomFile}"
}
while true; do
SetBG
sleep 20m
doneand yes, you will obviously have to start this process in the background every time you boot, best way to do it is to insert it in the autostart.sh (if you're on openbox, not sure where the autostart file is in xfce)
Offline
ervichu, have you thought about installing the missing package?
if not (and you want to) thensudo aptitude install feh
i was so dump to not think about installing feh:thanks a ton for replying
Offline
I replaced this
feh --bg-fill "${RandomFile}"with
nitrogen --set-fill "$RandomFile"I hope that's the setting for "zoomed fill" within nitrogen. Also, I couldn't find the autostart.sh file within openbox. Is there a way to insert it into conky to run at startup?
Offline
you should check nitrogen --help in a terminal
the zoomed fill (At least in my nitrogen version) is --set-zoom-fill
as for the autostarting the autostart.sh script is under your /home/*****/.config/openbox/autostart.sh
you CAN place that in your conky using ${exec path/to/script} but i would recommend you use autostart.sh instead since conky is not really meant for that kind of stuff
Offline
so I did some reading on the autostart.sh script, but I'm still unsure if I wrote the command correctly to execute the script.
exec /home/sunfizz98/bin/randomize_wallpaper.sh &I was also wondering if there was a way to make this random wallpaper script to work for multiple users, rather than individualize them for each user. I have all my wallpapers stored within dropbox. I would like to use a more flexible script within my dropbox folder and only have to edit the autostart.sh script to invoke them.
Offline
so what's wrong with this one?
and you don't need the exec in front of the path
Last edited by ali (2011-06-15 15:53:50)
Offline
@ali
Your script works like a charm in openbox, but it seems to crash my conky and give me a black background in my xfce environment. I thought it was just nitrogen so I tried out feh, but both give the same result.
Last edited by sunfizz98 (2011-08-27 22:22:41)
Offline
Offline
Offline
if i remember correctly xfce does not use feh nor nitrogen to set up the wallpaper
try searching for a command line to set the xfce4 wallpaper and simply replace the nitrogen/feh line in the script
i haven't searched very much for it but try this
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s <image-file>and conky and the script are unrelated (unless you put the script in conky)
Offline
When I try to run this script, this happens:
dan@crunchbang:~$ sh .scripts/wallpaper.sh
.scripts/wallpaper.sh: 24: arithmetic expression: expecting primary: " % 17 "Yes, my avatar is an octopus.
Offline
@SuNjACk: Thanks for the script
Modified it for nitrogen and removed the loop. I will try putting it into a cron job to run every X hours/whatever.
• Support #! • Waldorf • Debian sid • Xubuntu • siduction • Peppermint • OpenBox • Xfce • LXDE •
Offline
Sigh. cron can be a real pain sometimes. I've modified the script:
#!/bin/bash
/bin/date >> /tmp/test1 # TO CHECK THE CRON JOB IS RUNNING
Dir="/home/XXX/images/wallpapers"
if [ ! -d "$Dir" ]; then
echo "$Dir does not exist"
exit 1
fi
SetBG () {
TotalFiles=$( ls -1 "$Dir" | grep jpg | wc -l )
RandomNumber=$(( $RANDOM % $TotalFiles ))
test ! $RandomNumber = 0 || RandomNumber=1
RandomFile="$( ls -1 $Dir | head -n $RandomNumber | tail -n 1)"
echo "$Dir"/"$RandomFile" >> /tmp/test1 # TO CHECK
/usr/bin/nitrogen --set-scaled "$Dir"/"$RandomFile"
}
SetBGThis is saved as ~/images/wallpapers/random.sh and is chmod to 744. If I run the script on it's own, the wallpaper changes.
I setup a new cron job:
* * * * * /home/XXX/images/wallpapers/random.shAnd then tail the /tmp/test1 file. Every minute, the date and the full path and filename are appended to the file, so the script is running every minute. I've even inserted the path for nitrogen, but still the wallpaper will not change every minute.
Setting the wallpaper manually to "1.jpg" and then hard-coding the script (commenting out the existing nitrogen line and adding a new one) to set it to "2.jpg" also does not work. Adding the "--save" parameter to nitrogen also does not work. Clearly there is a trick to using nitrogen in cron...?
Last edited by SabreWolfy (2012-01-08 13:35:23)
• Support #! • Waldorf • Debian sid • Xubuntu • siduction • Peppermint • OpenBox • Xfce • LXDE •
Offline
I went through this particular pain a few weeks ago (including writing the time to a test file to make sure the script was running
). Apparently, cron can't access the display without explicit instructions.
Here's the crontab that is working for me:
*/10 * * * * DISPLAY=:0.0 /home/bsh/.scripts/random-wallpaperLet me know if it works.
Be eggsalad to each other.
Offline
^ Thanks! Just now found your thread on this ...
Edit: w00t! It works
Thanks 
Last edited by SabreWolfy (2012-01-08 13:41:10)
• Support #! • Waldorf • Debian sid • Xubuntu • siduction • Peppermint • OpenBox • Xfce • LXDE •
Offline
You're very welcome. That was a painful learning experience for me, especially after it stopped working for no apparent reason and then started working again for reasons I still don't understand. I really started to hate cron. 
Be eggsalad to each other.
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.