SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2013-07-29 12:29:23

Tasulian
New Member
Registered: 2013-07-29
Posts: 2

Dual Monitor Nitrogen Wallpaper Script

I have a dual monitor set up, and Nitrogen has the cool feature of being able to set separate wallpapers on each screen. However, I have been trying to set it up so that I can change wallpapers randomly as well. It's proven a bit complicated, but I've come up with a workaround. I found a script that will select a random wallpaper from a folder and change it. However, it does not support dual monitors.

 
#! /bin/bash
#using the path WALLPAPERS will select a new random wallpaper
WALLPAPERS="/filepath/to/wallpapers"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
nitrogen --set-scaled --save $WALLPAPERS/${ALIST[$number]}
exit

Since Nitrogen does not appear to have a command line way of specifying individual monitors, I had to improvise a bit. I modified the script to change the values stored in bg-saved.cfg before issuing the --restore command to nitrogen.

#! /bin/bash
#using the path WALLPAPERS will select a new random wallpaper
WALLPAPERS="/filepath/to/wallpapers"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last 
sed -i '7 c\file='$WALLPAPERS/${ALIST[$number]}'' /home/user/.config/nitrogen/bg-saved.cfg
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last 
sed -i '12 c\file='$WALLPAPERS/${ALIST[$number]}'' /home/user/.config/nitrogen/bg-saved.cfg
nitrogen --restore
exit

I'm definitely a newbie when it comes to scripting, so if there's an easier way to do this, I'd love to hear about it (For example, what's the most efficient way to code this without so many repeating lines?) As it is, I now have a cron job that uses this script to change my wallpapers on both monitors!

Offline

Be excellent to each other!

#2 2013-07-29 12:51:01

pidsley
Window Mangler
Registered: 2012-05-23
Posts: 1,752

Re: Dual Monitor Nitrogen Wallpaper Script

Last edited by pidsley (2013-07-29 13:48:20)

Offline

#3 2014-08-24 16:20:09

tariqk
New Member
From: Kuala Lumpur
Registered: 2014-08-24
Posts: 2

Re: Dual Monitor Nitrogen Wallpaper Script

#!/bin/bash

# Select random wallpaper for each screen, by fiddling with the configuration file for nitrogen.
# TODO: Modify to use getops, allowing you to specify config file locations, etc.
# TODO: Modify to use an RC file, so that rather than looking at hardcoded shit in this script you go somewhere else. 

CONFIG="$HOME/.config/nitrogen/bg-saved.cfg" # Replace this with whatever the nitrogen config file is.
WALLPAPERDIR="$HOME/wallpapers/"

function setwallpaper {
    # Modify the nitrogen configuration file (default location set in $CONFIG).
    # $1: Line to modify
    # TODO: Modify it so that rather than use a line to modify this, we just use the screen name.
    # Other potential features: allow you to use different modes rather than centre-and-zoom.
    WALLPAPER=`find $WALLPAPERDIR -type f | grep -E "jpeg|jpg|png" | shuf -n1`
    echo "$(date -u) -- Setting line $1 to $WALLPAPER."
    sed -i "$1 c\file=$WALLPAPER" $CONFIG
    }

setwallpaper 7   # screen 1, defined in line #7
setwallpaper 12  # screen 2, defined in line #12

# Refresh Nitrogen with new wallpaper.
nitrogen --restore

Offline

#4 2014-08-24 18:13:45

hrnn187
Member
Registered: 2014-07-29
Posts: 20

Re: Dual Monitor Nitrogen Wallpaper Script

Offline

#5 2015-01-07 08:03:02

OrganizedFellow
#! Member
Registered: 2014-09-02
Posts: 59

Re: Dual Monitor Nitrogen Wallpaper Script

#!/bin/sh

FOLDER=/home/jaimito/Dropbox/wallpaperstapet/
SELECT=ls -t | head -n 1



nitrogen --save --set-scaled /home/jaimito/Dropbox/wallpaperstapet/${SELECT}

exit

Offline

#6 2015-01-07 08:22:38

machinebacon
#! unstable
From: China
Registered: 2009-07-02
Posts: 6,826
Website

Re: Dual Monitor Nitrogen Wallpaper Script

Something like

#!/bin/bash

WALLS=/home/$USER/wallpapers
# show newest (last modified) file in $WALLS
NEWPIC=`ls $WALLS -tp | grep -v /$ | head -1`

nitrogen --save --set-scaled $WALLS/$NEWPIC

Untested, but should work.

Offline

#7 2015-03-08 03:33:15

pingu
#! Junkie
Registered: 2014-12-05
Posts: 367

Re: Dual Monitor Nitrogen Wallpaper Script

#!/bin/bash

# Select random wallpaper for each screen, by fiddling with the configuration file for nitrogen.
# TODO: Modify to use getops, allowing you to specify config file locations, etc.
# TODO: Modify to use an RC file, so that rather than looking at hardcoded shit in this script you go somewhere else. 

CONFIG="$HOME/.config/nitrogen/bg-saved.cfg" # Replace this with whatever the nitrogen config file is.
WALLPAPERDIR="$HOME/wallpapers/"

function setwallpaper {
    # Modify the nitrogen configuration file (default location set in $CONFIG).
    # $1: Line to modify
    # TODO: Modify it so that rather than use a line to modify this, we just use the screen name.
    # Other potential features: allow you to use different modes rather than centre-and-zoom.
    WALLPAPER=`find $WALLPAPERDIR -type f | grep -E "jpeg|jpg|png" | shuf -n1`
    echo "$(date -u) -- Setting line $1 to $WALLPAPER."
    sed -i "$1 c\file=$WALLPAPER" $CONFIG
    }

setwallpaper 7   # screen 1, defined in line #7
setwallpaper 12  # screen 2, defined in line #12

# Refresh Nitrogen with new wallpaper.
nitrogen --restore

Last edited by pingu (2015-03-08 03:41:33)


"We don't merge kernel code just because user space was written by a retarded monkey on crack."
Linus f****g Trovalds

Offline

#8 2015-09-14 20:59:44

LaneLester
Member
From: North Georgia, NA
Registered: 2010-03-22
Posts: 31
Website

Re: Dual Monitor Nitrogen Wallpaper Script

Last edited by LaneLester (2015-09-14 21:25:15)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo