59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
EXEC_SHELL_PATH=$(command -v bash)
|
|
|
|
lua=$(which lua)
|
|
pid=$$
|
|
"$lua" <<EOF
|
|
-- Set the directory containing the wallpapers
|
|
local wallpaper_dir = "~/wallpapers"
|
|
|
|
-- Get a list of all files in the directory
|
|
local files = {}
|
|
for file in io.popen("find " .. wallpaper_dir .. " -type f -print0 | xargs -0 -I {} echo {}"):lines() do
|
|
table.insert(files, file)
|
|
end
|
|
|
|
print("Files:")
|
|
for i, file in ipairs(files) do
|
|
print(file)
|
|
end
|
|
|
|
-- Create a pid file to store the process ID
|
|
local pid_file = "/tmp/wallpapers.pid"
|
|
local pid = io.open(pid_file, "w")
|
|
pid:write(tostring($pid))
|
|
pid:close()
|
|
|
|
-- Set the process name
|
|
local cmdline_file = "/proc/$pid/comm"
|
|
local cmdline = io.open(cmdline_file, "w")
|
|
cmdline:write("wallpapers")
|
|
cmdline:close()
|
|
|
|
while true do
|
|
-- Read true random data from /dev/random
|
|
local random_file = io.open("/dev/random", "rb")
|
|
local random_bytes = random_file:read(4)
|
|
random_file:close()
|
|
|
|
-- Convert the random bytes to a Lua number
|
|
local random_number = 0
|
|
for i = 1, #random_bytes do
|
|
random_number = random_number * 256 + string.byte(random_bytes, i)
|
|
end
|
|
|
|
-- Use the random number to select a wallpaper
|
|
local wallpaper_index = random_number % #files + 1
|
|
local random_wallpaper = files[wallpaper_index]
|
|
|
|
print("Random wallpaper:", random_wallpaper)
|
|
|
|
-- Set the wallpaper with feh, escaping the filename properly
|
|
local command = "feh --bg-fill '" .. random_wallpaper:gsub("'", "'\\''") .. "'"
|
|
os.execute(command)
|
|
|
|
-- Wait 30 seconds before changing the wallpaper again
|
|
os.execute("sleep 30")
|
|
end
|
|
EOF
|
|
|