You are not logged in.

#1 2013-01-05 01:12:35

Aquila
Member
Registered: 2012-12-23
Posts: 46

How to randomly change wallpaper in Awesome 3.5?

Hello there,

Sorry this may be a noob question.

In the rc.lua file of Awesome 3.5, the wallpaper is set like this.

for s = 1, screen.count() do
gears.wallpaper.maximized("Your wallpaper here", s, true)
end

How would I go about making this randomly choose wallpapers from a directory?

Thanks

Offline

#2 2013-01-05 01:27:40

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: How to randomly change wallpaper in Awesome 3.5?

I don't have any experience with awesome wm, but you can always use this little script/one-liner:

#!/bin/bash
find $HOME/.wallpapers -type f -name '*.jpg' -o -name '*.png' | shuf -n 1 | xargs feh --bg-scale

Last edited by illusionist (2013-01-05 01:28:49)


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#3 2013-01-05 01:40:33

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 438

Re: How to randomly change wallpaper in Awesome 3.5?

The gears module is basically just a setter.

You could use a timer with some code in the body to select the random wallpaper to feed into gears. This is my vpn timer as an example: http://sprunge.us/YcHB

(or you can just use an external wallpaper setter)

Last edited by tdy (2013-01-05 01:41:08)


dots (or just the awesomewm config)

$ whatis this?
this?: nothing appropriate.

Offline

#4 2013-01-06 02:21:38

Aquila
Member
Registered: 2012-12-23
Posts: 46

Re: How to randomly change wallpaper in Awesome 3.5?

Hey there,

One more quick question.
Is there a way for the gears module to randomly choose an image from a directory?

Thanks

Offline

#5 2013-01-06 05:52:33

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 438

Re: How to randomly change wallpaper in Awesome 3.5?

No, that link shows the gears wallpaper API


dots (or just the awesomewm config)

$ whatis this?
this?: nothing appropriate.

Offline

#6 2013-01-06 06:35:53

ignorant
Member
Registered: 2012-06-09
Posts: 50

Re: How to randomly change wallpaper in Awesome 3.5?

There are a few ways you can do it. Here's two ways I came up with:

A list of files:

local wallpapers = {
  os.getenv("HOME") .. "/.wallpaper/foo1.png",
  os.getenv("HOME") .. "/.wallpaper/foo2.png"
}
math.randomseed(os.time());
local wallpaper = wallpapers[math.random(1, #wallpapers)]
for s = 1, screen.count() do
  gears.wallpaper.maximized(wallpaper, s, true)
end

A directory full of files:

local f = io.popen("sh -c \"find ~/.wallpaper -name '*.png' | shuf -n 1 | xargs echo -n\"")
local wallpaper = f:read("*all")
f:close()
for s = 1, screen.count() do
  gears.wallpaper.maximized(wallpaper, s, true)
end

warning: this code isn't tested as much as it should be.

Last edited by ignorant (2013-01-06 09:42:49)

Offline

#7 2013-01-09 14:48:50

williamguerra
Member
Registered: 2013-01-09
Posts: 1

Re: How to randomly change wallpaper in Awesome 3.5?

I have my own wallpaper.sh

#!/bin/sh

find ~/pictures/wallpapers/current/ -type f \( -name '*.jpg' -o -name '*.png' \) -print0 |
		shuf -n1 -z | xargs -0 feh --bg-fill

I would like to run it on startup, but the theme.wallpaper_cmd field in the theme.lua doesn't seem to be working anymore. Also the gears api doesnt look like it has an argument for this kind of thing. Where can I put an execution to this script?

Last edited by williamguerra (2013-01-09 14:49:15)

Offline

#8 2013-01-09 15:58:51

chris_l
Member
Registered: 2010-12-01
Posts: 387

Re: How to randomly change wallpaper in Awesome 3.5?

Have you tried with the methods the wiki article gives?
https://wiki.archlinux.org/index.php/Fe … ound_image
EDIT: The cron job method is probably the way more easy.

Last edited by chris_l (2013-01-09 16:02:36)


"open source is about choice"
No.
Open source is about opening the source code complying with this conditions, period. The ability to choose among several packages is just a nice side effect.

Offline

#9 2013-01-09 16:11:06

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,336
Website

Re: How to randomly change wallpaper in Awesome 3.5?

Perhaps you can adapt a project I started for xfce4 called backdrop randomizer.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#10 2013-01-10 14:51:23

cephalopoid
Member
Registered: 2009-08-05
Posts: 21

Re: How to randomly change wallpaper in Awesome 3.5?

I use the following script, put in my ~/bin/, which I've put in my $PATH.

#!/bin/bash

export bg=$(find "$1" -maxdepth 1 -mindepth 1 -type f -print0 \
  | sort --zero-terminated --random-sort \
        | sed 's/\d000.*//g')
feh --no-fehbg --bg-max "$bg"

I called it backgroundsetting and it takes a directory as an argument. I can't be bothered to make the script do more though.

My wallpaper setting in the theme file looks like this, but it's not that relevant, as it gets overridden by the above script, put in my .xinitrc:

theme.wallpaper = "/home/cephalopoid/pics/wp/somewallpaper.jpg"

ADDENDUM: Never mind, I didn't read the first post properly. Am posting this anyway, might help people.

Offline

#11 2013-01-10 19:47:17

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,001
Website

Re: How to randomly change wallpaper in Awesome 3.5?

Use cron. It only takes adding one line with

$ crontab -e

0 * * * * DISPLAY=:0.0 feh --bg-scale --no-fehbg `find ~/wallpaper/ | shuf -n1`

Offline

#12 2013-03-14 05:12:53

teratomata
Member
Registered: 2010-02-23
Posts: 13

Re: How to randomly change wallpaper in Awesome 3.5?

I hope this isn't resurrecting a dead thread, but I wrote an almost purely lua version (with ls and grep) based off of these comments, stackoverflow for scandir in lua, and the awesome wiki's 3.4 wallpaper changer.

-- {{{ Random Wallpapers

-- Get the list of files from a directory. Must be all images or folders and non-empty. 
    function scanDir(directory)
	local i, fileList, popen = 0, {}, io.popen
	for filename in popen([[find "]] ..directory.. [[" -type f]]):lines() do
	    i = i + 1
	    fileList[i] = filename
	end
	return fileList
    end
    wallpaperList = scanDir("/home/david/Images/Wallpaper SFW")

-- Apply a random wallpaper on startup.
    gears.wallpaper.maximized(wallpaperList[math.random(1, #wallpaperList)], s, true)

-- Apply a random wallpaper every changeTime seconds.
    changeTime = 600
    wallpaperTimer = timer { timeout = changeTime }
    wallpaperTimer:connect_signal("timeout", function()
	gears.wallpaper.maximized(wallpaperList[math.random(1, #wallpaperList)], s, true)

    -- stop the timer (we don't need multiple instances running at the same time)
        wallpaperTimer:stop()

    --restart the timer
        wallpaperTimer.timeout = changeTime
        wallpaperTimer:start()
    end)

    -- initial start when rc.lua is first run
    wallpaperTimer:start()
-- }}}

Last edited by teratomata (2013-03-14 05:28:17)

Offline

#13 2013-04-07 21:47:03

Devcon
Member
Registered: 2010-03-07
Posts: 9

Re: How to randomly change wallpaper in Awesome 3.5?

tera,

Just wanted to say thanks for the script.  I normally just do it in bash like most folks, but I like having a mostly LUA solution.

Offline

Board footer

Powered by FluxBB