Page 1 of 1

Random conky slideshow

Posted: Thu Jul 28, 2011 9:14 am
by Roken
I wrote this script for myself, but thought I'd share in case anyone wants it. It's a script to generate a random slideshow for use in conky (though there are other uses if you modify it a little).

The script reads a config file containing three lines, the first being the path to pictures to include, the second is the delay between picture changes and the third is the size of the image as shown in conky. eg:

Code: Select all

/home/username/Pictures
30
160x120
Create your config file in your home directory and call it .conkypic

To add the slideshow to conky, include the following in .conkyrc

Code: Select all

${image /dev/shm/conkypic.png -p 70,95 -n}
(Adjust the -p parameters to suit)

You may want to set the script to run at system startup by adding it to startup applications.

The script itself:

Code: Select all

#!/bin/bash
# Have the script recognise spaces in directory paths and filenames
IFS='
'
#Now we need to check if the script is already running. For some odd reason it seems to survive after a relog
PDIR=${0%`basename $0`}
LCK_FILE=`basename $0`.lck
if [ -f "${LCK_FILE}" ]; then
	MYPID=`head -n 1 "${LCK_FILE}"`
	TEST_RUNNING=`ps -p ${MYPID} | grep ${MYPID}`

	if [ -z "${TEST_RUNNING}" ]; then
		# It's not running, let's signal that
		echo $$ > "${LCK_FILE}"
	else
		# An instance is already running. Exit gracefully
		exit 0
	fi
else
	echo $$ > "${LCK_FILE}"
fi

#This is the main bit
done="yes"
while [ $done = "yes" ]
do
	# Read the config file
	exec 3<> ~/.conkypic
	read <&3 dirpath
	read <&3 timeout
	read <&3 as
	exec 3>&-
	# Nopw get a liist of files
	cd $dirpath
	files=(`ls -1 *.[Jj]??`)
	len=${#files[*]}

	if [ "$len" != "0" ]; then
		# Pick a file at random
		number=$RANDOM
		let "number %= $len"
		# Now we copy it a temporary location. The following copies to RAM. If you are short
		# on memory change the location to somewhere in /home
		cp "${wd}${files[$number]}" /dev/shm/conkypic.jpg
		# Convert the image for conky
		mogrify -format png -resize $as /dev/shm/*.jpg &
	fi
	# Wait before repeating
	sleep $timeout
done
Enjoy

Edit: It's currently setup to accept jpg as input files. If you want to add other files (eg png) change the line "files=(`ls -1 *.[Jj]??`)" to "files=(`ls -1 *.[JPjp]??`)". Note that this is very basic matching and there is no error checking. Best to use a folder as the source with only picture files.

Re: Random conky slideshow

Posted: Thu Jul 28, 2011 10:00 am
by lmintnewb
Neat ... thanks for sharing. Hmmmm, do ya think my gf will get upset if I use this for p0rn related applications ? Hmmmmm ... any chance of ya teaching me some bash to hide this thing when I press a certain shortcut key ? ;)

Messing o course, well not about the ty.

Re: Random conky slideshow

Posted: Thu Jul 28, 2011 10:50 am
by Habitual
Good job Roken!

Oh boy, conky+shell scripts. I spent about 6 months dorking with this stuff, so here's my contribution.

It grabs the daylight map (your choice of graphic size) and sticks it on the desktop using conky.
The goal was to have a "moving" map of the daylight on my desktop.
Image

The constructor author of the static.die.net site used xplanet to do the work which you can do also,
but I was addicted to conky at the time. I'm over it now, Thank you,

Of course, the gnome clock|date > locations has this feature also, but it is quite small. And where's the fun in that? :wink:

There are 3 files attached that get the job done.
"cron.txt" ---> goes in your cron and updates every 30 minutes (more frequent updates will fail -- hotlink protection mechanism?)
"daylight" ---> is the actual conky configuration (rc) file?
"daylight.sh" is the bash script that cron runs.

2 good examples of bash creativity and flexibility.
I hope that someone gains something from these posts. :)

Re: Random conky slideshow

Posted: Thu Jul 28, 2011 11:22 am
by Roken
Nice, Habitual. Perhaps we could make this a repository for random conky helper scripts :)

It's nice to do something with bash from time to time that actually prettifies the desktop, rather than just beavering away with system maintenance.

BTW, I should have mentioned that the with the slideshow script the config file (.conkypic) can be changed on the fly - no need to kill and restart the script.

Re: Random conky slideshow

Posted: Thu Jul 28, 2011 9:12 pm
by Habitual
Roken wrote:Nice, Habitual. Perhaps we could make this a repository for random conky helper scripts :)
Thanks.
But I don't subscribe to "random".
Roken wrote:...a repository for random conky helper scripts...
It's a gray area, it way gray and I was in the area. :wink:

I have to quench the "need" to post TMI (usually unsubscribed or unrequested info/scripts/whatnot).
**Shrug**
I'll work on it.

Re: Random conky slideshow

Posted: Wed Aug 03, 2011 6:02 am
by Roken
Slightly modified version of the random picture script. This one traps termination signals and cleans up after itself. Also, the lock file is now stored in ~/ while the program is running.