![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
|
|
Absolute Beginner Talk The perfect starting place to find out more about computers, Linux and Ubuntu. |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Just Give Me the Beans!
![]() Join Date: Jul 2006
Beans: 61
|
Wallpaper changing shell script
Hi, I have searched this forums for a way to make wall papers change randomly. Now this is something so simple I was sure I could find an easy program. Unfortunately all the things seem to be pretty buggy or did not run or had problems. Thus, I was forced to learn about shell scripting and then how to use cron (hey, i should learn these things anyway). Anyway, here is code from somewhere that I found:
Code:
#!/bin/sh #Go to our pics cd /media/documents/Desktops #Get all the picture files names IMGS=`find . -iname '*.jpg' -o -iname '*.png' -o -iname '*.svg'` #Find out how many pictures we got N=`echo $IMGS | wc -w` #Take a random number between 1 and N ((N=RANDOM%N)) #Cut the file to get the n'th picture BGNAME=`echo $IMGS | cut -d '/' -f $N | cut -d ' ' -f 1` #Call upon gconftool to write into the "registry" gconftool-2 -t str --set /desktop/gnome/background/picture_filename "/media/documents/Desktops/$BGNAME" |
|
|
|
|
|
#2 |
|
Just Give Me the Beans!
![]() Join Date: Jul 2006
Beans: 61
|
Re: Wallpaper changing shell script
On second thoughts, (although I will not prefer this alternative), is it possible to rename all files with spaces to files with underscores or other characters?
|
|
|
|
|
|
#3 |
|
A Carafe of Ubuntu
![]() Join Date: Jul 2006
My beans are hidden!
Kubuntu 7.10 Gutsy Gibbon
|
Re: Wallpaper changing shell script
you could try this nifty shell script
Code:
#! /bin/bash
# blank-rename.sh
#
# Substitutes underscores for blanks in all the filenames in a directory.
ONE=1 # For getting singular/plural right (see below).
number=0 # Keeps track of how many files actually renamed.
FOUND=0 # Successful return value.
for filename in * #Traverse all files in directory.
do
echo "$filename" | grep -q " " # Check whether filename
if [ $? -eq $FOUND ] #+ contains space(s).
then
fname=$filename # Yes, this filename needs work.
n=`echo $fname | sed -e "s/ /_/g"` # Substitute underscore for blank.
mv "$fname" "$n" # Do the actual renaming.
let "number += 1"
fi
done
if [ "$number" -eq "$ONE" ] # For correct grammar.
then
echo "$number file renamed."
else
echo "$number files renamed."
fi
exit 0
|
|
|
|
|
|
#4 |
|
Just Give Me the Beans!
![]() Join Date: Jul 2006
Beans: 61
|
Re: Wallpaper changing shell script
... the funny thing is that about the same lines of code were used to maintian correct grammar. thanks for that suggestion, but before i go doing some mass 1000+ files file renaming, I would like to find a way to keep the names.
heaps of pictures like these ![]() |
|
|
|
|
|
#5 |
|
Just Give Me the Beans!
![]() Join Date: Jul 2006
Beans: 61
|
Re: Wallpaper changing shell script
This is the final solution. It works for any thing as long as all pictures are in the directory, regardless of name formatting, subdirectories or hard links(not sure about that one though)
Code:
#!/bin/sh
# Set your folder with the pics
picsfolder="/media/documents/Desktops/"
# Go to your folder with the pics
cd $picsfolder
# Create an array of the files
files=(./*/*.jpg)
# Get the size of the array
N=${#files[@]}
# Select a random number between this range
((N=RANDOM%N))
# Get the name of this file
randomfile=${files[$N]}
# start of gconftool command and set the desktop
gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$picsfolder$randomfile"
|
|
|
|
|
|
#6 | |
|
A Carafe of Ubuntu
![]() |
Re: Wallpaper changing shell script
So if I copy this script, what kind of file do I save it as?
Quote:
__________________
Love my Stego - Happiest Geek Gal in fandom! |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|