You are not logged in.
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
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
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)
Offline
Hey there,
One more quick question.
Is there a way for the gears module to randomly choose an image from a directory?
Thanks
Offline
No, that link shows the gears wallpaper API
Offline
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
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
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
Perhaps you can adapt a project I started for xfce4 called backdrop randomizer.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
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
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
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
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