Find the answer to your Linux question:
Results 1 to 2 of 2
As an user arrested in the newbie stage, I can't contribute much with most questions, but I think I've found something mildly interesting to offer (besides just the idea of ...
  1. #1
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    211

    Script sharing, useful or just eye-candy

    As an user arrested in the newbie stage, I can't contribute much with most questions, but I think I've found something mildly interesting to offer (besides just the idea of a topic to share scripts).

    I have two scripts (it's possible to fuse into just one, but I don't know if it would have any benefit) that work conjointly in order to produce a sort of screensaver-like slideshow/wallpaper changer, at least for openbox and fluxbox, or whatever that can have its wallpaper set with Esetroot (that is, without further adaptation to some other wallpaper "engine", which certainly is possible too).



    The amazing screensaver-like wallpaper randomizer

    Basically there's the "screensaver" script, which will infer from /proc/interrupt whether there were mouse movements within a given time interval, and if there were none, it will call a wallpaper randomizer script.

    I think it may be better than changing the wallpaper within rigid time intervals because sometimes you're doing something and there may be some sluggishness as the wallpaper changes to a image from a large file, at least in slower computers. Tracking the mouse movement theoretically avoids that.

    It's also possible to track other sorts of activity, like certain programs being running too, which may further avoid this issue, if someone uses a program that does not require to use the mouse much.


    I can't claim the authorship of these scripts, they're tiny frankensteinian patchworks/hacks from other scripts I've found on forums such as this, linuxquestions, and maybe ubuntu's, thanks for the real authors, whoever they might be .Here are the scripts:



    Code:
    #!/bin/bash
    # mouseup rm200702018
    # A script [originally] for testing user activity on mouse
    # and shutting down if none - adapted to work as a
    # screensaver-like wallpaper-changer. Should run
    # in the background.
    
    TIME=3m #set time between checks, "m" suffix for minutes
    
    until ((1==2)) 
    do
    
    # The original script used "grep 12" to find the mouse; it
    # wasn't working for me. I've found this number 21 inferring
    # from the output of "cat /proc/interrupts" on command line.
    
    MOUSE1=`cat /proc/interrupts | grep 21: | awk '{print $2}'`
    
    echo "`date` MOUSE1 equals $MOUSE1" >> log.txt
    
    sleep $TIME
    
    
    # Same caveat as previously mentioned, may have to adjust
    # the number on "grep".
    
    MOUSE2=`cat /proc/interrupts | grep 21: | awk '{print $2}'`
    echo "`date` MOUSE2 equals $MOUSE2" >> log.txt
    
    
    if [ $MOUSE1 -eq $MOUSE2 ] ; then
    echo "`date` changing wallpaper" >> log.txt
    ~/wallpapers/./randomwallpaper
    fi
    done
    
    
    # End of script



    The wallpaper randomizer it calls:

    Code:
    # the next part was supposed to verify whether the  slideshow
    # is running or not, runs it, if it is not - useful to reactivate the
    # slideshow automatically whenever the user requests a 
    # random wallpaper via keybind or rootmenu (not working
    # now, it but does not affect the overall functioning of the scripts) 
    
    if [ ! -f ~/.slideshowon ]
    then
        ~/wallpapers/./wallpaperslideshow
    else
    
    
    # The messy randomization process:
    
    maindir=~/wallpapers/images
    
    
    subdir=$(find ${maindir}/* -type d)
    subd=($subdir)
    numsub=${#subd[*]}
    
    n=$RANDOM%numsub
    
    #echo ${subd[$((n))]}
    
    Background=$(find ${subd[$((n))]} -iname '*')
    background=($Background)                # Read into array variable.
    num_background=${#background[*]}        # Count how many elements.
    a=$RANDOM%num_background
    
    
    
    # the following sequence is not strictly necessary, just helps 
    # keeping track of the recent wallpapers 
    
    rm ~/wallpapers/old/*
    mv ~/wallpapers/last/* ~/wallpapers/old/
    mv ~/wallpapers/current/* ~/wallpapers/last/
    ln -s ${background[$((a))]} ~/wallpapers/current/
    
    echo ${background[$((a))]} >> ~/wallpapers/wphistory
    
    
    
    # Actually sets the wallpaper:
    
    Esetroot -fit "${background[$((a))]}">> ~/wallpapers/wphistory2 
    
    
    # This might be useful if you use xdkcal, but in my experience it only needs to be "huped" once, on the startup script (xinitrc or equivalent):
    
    #pkill -HUP xdkcal
    
    fi

    The directory structure it requires as it is right now, is the following:

    /home/user/wallpapers/ - scripts here

    /home/user/wallpaper/images/ - subdirectories (just one
    level) with actual image files (or links to image files) here

    Images on the root of the "images" directory will be ignored, it requires at least one subdirectory. With thousands of images, the randomization can get slow, which does not really matter if you don't use a keybind or an menu command to get a random wallpaper, but if you do, it just feels somewhat weird. The way I've found to circumvent it was to parse the randomization into two stages.

    Apparent bugs and limitations I'm trying to work on:

    - I'm almost sure it will every now and then it will get some image from the user's root directory (if there is any), not from the correct folders. I couldn't yet find why, neither a pattern on it. My suspicion is that it has something to do with dead and "reborn" link-files, if it does exist, but I'm not sure.

    - I couldn't yet find out how to arrange the Esetroot command line to deal with file names with spaces.


    Credits, or something like it

    The "screensaver" part was adapted mainly from here, some posts have material that may be useful to make it inactive if some program is running, even if the mouse is not moving for a few minutes. The other one had some help here in this forum, in an earlier topic.



    That's it. I hope someone finds it "useful".
    Last edited by the dsc; 12-02-2008 at 04:37 PM. Reason: ortography & grammar

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Instead of

    Code:
    MOUSE2=`cat /proc/interrupts | grep 21: | awk '{print $2}'`
    you should say

    Code:
    MOUSE2=$(awk '/21:/ { print $2; }' /proc/interrupts)
    One process instead of three.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...