Greetings, so long that I have not collaborated with anything on the blog (more than a comment lost there) makes me happy to be able to do so in such a beautiful change that the blog received.
Today I bring something very used and very spoken everywhere, but with a little twist.
Itself is a small script en bash entirely written by me (which I greatly appreciate the different posts of DesdeLinux that helped me do it) that serves simply to change desktop background automatically every so often.
So what's new old?
Various little things. First use nitrogen, which makes it lightweight. The script causes the background to be changed in a random time. It also checks the folder and its sub-folders automatically. The best thing is that every time the background changes it informs you with a notification on the desktop 😉. And it can be modified to taste and pleasure since it is very simple.
Therefore I consider that you already have certain knowledge on the subject or if not, you will look for it on the blog or you will consult it.
Thanks for your understanding.
It must first be installed Nitrogen (come on, they already have to know how to do it), also optionally libnotify for notifications.
Without further ado, the script:
#Aquí va la carpeta con las imágenes (no importa si están en subcarpetas)
cd "~/Imágenes/Fondo Pantalla/"
#Comienzo del bucle. Como verán es infinito :)
while [ 0 -eq 0 ]; do
#Esto hace que el script:
#1 Busque todos los archivos con "find"
#2 Filtre solo los jpg con "grep jpg"
#3 Cuente cuantos archivos hay con "wc -l"
NITROGEN_CANTIDAD_DE_LINEAS=`find | grep jpg | wc -l`
#Me imagino que sabrán para que sirve esta linea ¬¬
echo "lineas $NITROGEN_CANTIDAD_DE_LINEAS"
#Esta linea elige un numero al azar con min. 1 y máx. el numero de archivos ya obtenido
NITROGEN_ELEGIR=$((1+RANDOM%$NITROGEN_CANTIDAD_DE_LINEAS))
echo "linea elegida: $NITROGEN_ELEGIR"
#Esto hace que el script:
#1 Busque todos los archivos con "find"
#2 Filtre solo los jpg con "grep jp"
#3 Seleccione la linea con "sed" usando la linea elegida anteriormente.
NITROGEN_WALLPAPER=`find | grep jpg | sed -n $((NITROGEN_ELEGIR))p`
echo $NITROGEN_WALLPAPER
#Por fin establecemos el fondo con el archivo elegido.
nitrogen --set-centered $NITROGEN_WALLPAPER
#Con esta linea elegimos un tiempo al azar con min. 4 y máx 120.
NITROGEN_TIEMPO=$((4+RANDOM%120))
#Esto envía una notificación al escritorio.
#Con la opción -i pueden elegir un icono.
#Y obvio que pueden cambiar el texto o eliminar si molesta con solo borrar/comentar la linea.
notify-send -t 10000 "CAMBIO DE FONDO DE ESCRITORIO" "\nEl fondo de pantalla a sido cambiado.\nEl próximo cambio se efectuara en $NITROGEN_TIEMPO segundos.\n\nEl misterioso cambiador de imágenes"
#Con esto esperamos el tiempo en segundos ya elegido antes.
sleep $((NITROGEN_TIEMPO))
#Aquí termina todo para volver a comenzar
done
Obviously that in the line you use "CD" they must place the path where they have their images.
Don't forget to make the file executable !!!
All that remains is to do it start automatically (although I advise trying it in a terminal) in your favorite environment.
How can you see I have very little desire to write, ha.
But I leave you to try it, especially it will be good for those who use a minimalist environment.
It is also quite educational, because it uses loops, variables, etc.
Hope you like!!!!
REGARDS!!!!!
Hello, thanks for the scrib, I was looking for something to change the wallpapers with nitro, just a little doubt with time, how do you handle time in seconds or minutes, because it sends me notifications very fast but it does not change from the first image you take, in advance and repeatedly thank you for your attention.
Hello!! Sorry for the delay.
The time is in seconds because I use Sleep for that.
On the line NITROGEN_TIEMPO = $ ((4 + RANDOM% 120))
The variable NITROGEN_TIME takes a random number between 4 and 120 and passes it to Sleep
Obviously you can delete the whole command $ ((4 + RANDOM% 120)) and set the amount of fixed seconds you want.
Remember that if you don't want the notification you can delete it.
Good Leo, it is perfect for me, I use nitrogen in my LXDE 😉
I'm glad it served you 😀
I don't understand why there are people who like to turn their desks into such carnivals. Anyway.
Good tip, although you already made me remember when I used webshots in Windows.
Very good Leo! Thanks 🙂
I'm going to try it in elementary 😛
Great script .. 😉
Thank you all for the comments 😀
A little bug.
In the first line that has the command cd does not work with ~/ but it has to be written / home / YOUR_USER / SELECT_FOLDER
Was it understood?
cd ~ / Pictures / Background \ Screen
cd «$ HOME / Images / Wallpaper»
cd ~ / Pictures / Background \ Screen
cd «$ HOME / Images / Wallpaper»
My «feedback»
It would be good if the blog had the option to preview, so it would avoid putting the same comment twice due to connection problems 🙂
Nice script, just one thing:
By using: find | grep jpg | wc -l
grep does "dry" filtering and you can use files like jpg.lua, it is best to use extension filtering:
find | grep '[.] jpg $' | wc -l
regards
I hadn't thought about it, good suggestion.