Random conky slideshow

Forum rules
Before you post please read how to get help

Random conky slideshow

Postby Roken on Thu Jul 28, 2011 9:14 am

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.
Kernel Linux Tex 3.2.2-1 (64 bit) xfce , burg
Arch
ATI Radeon HD 4670, 1GB
OSS4
AMD Phenom II X4 (965BE) @ 3.6 Ghz (Overclocked)
8Gb RAM
Image
User avatar
Roken
Level 5
Level 5
 
Posts: 747
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK

Linux Mint is funded by ads and donations.
 

Re: Random conky slideshow

Postby lmintnewb on Thu Jul 28, 2011 10:00 am

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.
lmintnewb
Level 7
Level 7
 
Posts: 1574
Joined: Fri Apr 01, 2011 5:13 pm

Re: Random conky slideshow

Postby Habitual on Thu Jul 28, 2011 10:50 am

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. :)
Attachments
Daylight.tar.gz
(1.8 KiB) Downloaded 58 times
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2254
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: Random conky slideshow

Postby Roken on Thu Jul 28, 2011 11:22 am

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.
Kernel Linux Tex 3.2.2-1 (64 bit) xfce , burg
Arch
ATI Radeon HD 4670, 1GB
OSS4
AMD Phenom II X4 (965BE) @ 3.6 Ghz (Overclocked)
8Gb RAM
Image
User avatar
Roken
Level 5
Level 5
 
Posts: 747
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK

Re: Random conky slideshow

Postby Habitual on Thu Jul 28, 2011 9:12 pm

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.
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2254
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: Random conky slideshow

Postby Roken on Wed Aug 03, 2011 6:02 am

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.
Attachments
randompic.tar.gz
(879 Bytes) Downloaded 49 times
Kernel Linux Tex 3.2.2-1 (64 bit) xfce , burg
Arch
ATI Radeon HD 4670, 1GB
OSS4
AMD Phenom II X4 (965BE) @ 3.6 Ghz (Overclocked)
8Gb RAM
Image
User avatar
Roken
Level 5
Level 5
 
Posts: 747
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests