From f6bac59182683dc8e5cee8fc3a6f59d403d781ca Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 17 Jul 2024 15:22:19 +0200 Subject: [PATCH] Ready. Set. Go! --- LICENSE | 25 +++++++++++++++++++++++++ README.md | 15 +++++++++++++++ autobg | 12 ++++++++++++ autobg.service | 9 +++++++++ autobg.timer | 9 +++++++++ setup.sh | 10 ++++++++++ ç | 9 +++++++++ 7 files changed, 89 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 autobg create mode 100644 autobg.service create mode 100644 autobg.timer create mode 100755 setup.sh create mode 100644 ç diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6658201 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2024, apio. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2000b00 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# autobg + +Shell script to automatically pick a new wallpaper from a folder every so often. Made for GNOME+systemd systems. + +## Usage + +Start by cloning the repo. + +Then, edit the files to your desired settings. The default setting is to change the wallpaper every two minutes, but you may want it to be more or less frequent. To change this, edit the "OnUnitActiveSec" field in [autobg.timer](autobg.timer) and enter the number of seconds. + +By default, the script picks a random wallpaper from `~/Pictures/Wallpapers`. If you'd like it to pick from a different folder, edit the path in [autobg](autobg). + +You can then run the shell script [setup.sh](setup.sh). It will copy the script to `~/.local/bin` and install the files needed by systemd to run it periodically. + +If you'd like to manually pick a new random wallpaper (without waiting for the timer), run `autobg` directly. diff --git a/autobg b/autobg new file mode 100755 index 0000000..8c32e45 --- /dev/null +++ b/autobg @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +import os, random + +os.chdir(os.path.join(os.path.expanduser("~"), "Pictures/Wallpapers")) + +files = (file for file in os.listdir() + if os.path.isfile(os.path.join(os.getcwd(), file))) + +wallpaper = random.choice(list(files)) + +os.system(f"gsettings set org.gnome.desktop.background picture-uri 'file:///{os.path.join(os.getcwd(),wallpaper)}'") +os.system(f"gsettings set org.gnome.desktop.background picture-uri-dark 'file:///{os.path.join(os.getcwd(),wallpaper)}'") diff --git a/autobg.service b/autobg.service new file mode 100644 index 0000000..50082a9 --- /dev/null +++ b/autobg.service @@ -0,0 +1,9 @@ +[Unit] +Description=Set random wallpaper on login + +[Service] +ExecStart=HOME/.local/bin/autobg +Type=oneshot + +[Install] +WantedBy=default.target diff --git a/autobg.timer b/autobg.timer new file mode 100644 index 0000000..c63fc71 --- /dev/null +++ b/autobg.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Set random wallpaper every two minutes + +[Timer] +OnActiveSec=1 +OnUnitActiveSec=300 + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..69e520d --- /dev/null +++ b/setup.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir -p ~/.local/bin +cp ./autobg ~/.local/bin/autobg +cp ./autobg.timer ~/.config/systemd/user/autobg.timer +cp ./autobg.service ~/.config/systemd/user/autobg.service +sed -i -e "s+HOME+$HOME+g" ~/.config/systemd/user/autobg.service +systemctl --user enable --now autobg.timer +systemctl --user enable autobg.service + diff --git a/ç b/ç new file mode 100644 index 0000000..e86c713 --- /dev/null +++ b/ç @@ -0,0 +1,9 @@ +[Unit] +Description=Set random wallpaper on login + +[Service] +ExecStart=~/.local/bin/autobg +Type=oneshot + +[Install] +WantedBy=default.target