Skip to content
Open
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# spotlight
Windows 10 Spotlight Background images for Gnome
Windows 10 Spotlight Background images for Gnome and KDE.

Tested on Ubuntu 20.04 and Kubuntu 22.04.

## Installation
### System-wide
Expand Down
69 changes: 69 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

# This script installs the relevant files as the current user. You can also use it to update
# the installation using "./install.sh update".

set -e

action="install"

if [ "$1" -a "$1" == "uninstall" ]; then
action="uninstall"
elif [ "$1" -a "$1" == "update" ]; then
action="update"
elif [ "$1" -a "$1" == "install" ]; then
action="install"
else
echo "error: unknown action (accepting 'install', 'update', and 'uninstall'), exiting."
exit 1
fi

if [ "$action" == "install" ]; then
sudo apt install jq wget sed libglib2.0-0 python3
mkdir -p ~/.local/share/systemd/user/
mkdir -p ~/.local/bin/

cp spotlight.desktop ~/.local/share/applications/spotlight.desktop
cp spotlight.timer ~/.local/share/systemd/user/spotlight.timer
cp spotlight.service ~/.local/share/systemd/user/spotlight.service
cp spotlight.sh ~/.local/bin/spotlight.sh
cp ksetwallpaper.py ~/.local/bin/ksetwallpaper.py
systemctl --user enable spotlight.timer
elif [ "$action" == "update" ]; then
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
git remote update > /dev/null 2>&1
UPSTREAM="master"
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
echo "Already up-to-date."
exit 0
fi
git pull
else
echo "Not in a git repository. Please change to the spotlight git repository, exiting."
exit 1
fi
systemctl --user stop spotlight.timer
cp spotlight.desktop ~/.local/share/applications/spotlight.desktop
cp spotlight.timer ~/.local/share/systemd/user/spotlight.timer
cp spotlight.service ~/.local/share/systemd/user/spotlight.service
cp spotlight.sh ~/.local/bin/spotlight.sh
cp ksetwallpaper.py ~/.local/bin/ksetwallpaper.py
systemctl --user enable spotlight.timer
else
systemctl --user stop spotlight.timer
systemctl --user disable spotlight.timer
rm -f ~/.local/share/applications/spotlight.desktop
rm -f ~/.local/share/systemd/user/spotlight.timer
rm -f ~/.local/share/systemd/user/spotlight.service
rm -f ~/.local/bin/spotlight.sh
rm -f ~/.local/bin/ksetwallpaper.py

# Delete directory only if it is empty:
if [ -z "$(ls -A ~/.local/share/systemd/user/)" ]; then
rm -rf ~/.local/share/systemd/user/
fi
fi

exit 0
107 changes: 107 additions & 0 deletions ksetwallpaper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python3
import time
import dbus
import argparse
import glob
import random
import os
import subprocess
from pathlib import Path
HOME = str(Path.home())
SCREEN_LOCK_CONFIG = HOME+"/.config/kscreenlockerrc"
def setwallpaper(filepath, plugin='org.kde.image'):
jscript = """
var allDesktops = desktops();
print (allDesktops);
for (i=0;i<allDesktops.length;i++) {
d = allDesktops[i];
d.wallpaperPlugin = "%s";
d.currentConfigGroup = Array("Wallpaper", "%s", "General");
d.writeConfig("Image", "file://%s")
}
"""
bus = dbus.SessionBus()
plasma = dbus.Interface(bus.get_object(
'org.kde.plasmashell', '/PlasmaShell'), dbus_interface='org.kde.PlasmaShell')
plasma.evaluateScript(jscript % (plugin, plugin, filepath))

def set_lockscreen_wallpaper(filepath,plugin='org.kde.image'):
if os.path.exists(SCREEN_LOCK_CONFIG):
new_data=[]
with open(SCREEN_LOCK_CONFIG, "r") as kscreenlockerrc:
new_data = kscreenlockerrc.readlines()
is_wallpaper_section=False
for num,line in enumerate(new_data,1):
if "[Greeter][Wallpaper]["+plugin+"][General]" in line:
is_wallpaper_section = True
if "Image=" in line and is_wallpaper_section:
new_data[num-1] = "Image="+filepath+"\n"
break

with open(SCREEN_LOCK_CONFIG, "w") as kscreenlockerrc:
kscreenlockerrc.writelines(new_data)

def is_locked():
is_locked=subprocess.check_output("qdbus org.kde.screensaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive",shell=True,universal_newlines=True).strip()
if is_locked == "true":
is_locked = True
else:
is_locked = False
return is_locked

def get_walls_from_folder(directory):
return glob.glob(directory+'/*')


def wallpaper_slideshow(wallapapers, plugin, timer, lock_screen):
if timer > 0:
wallpaper_count = len(wallapapers)
delta_s = timer
s = int(delta_s % 60)
m = int((delta_s / 60) % 60)
h = int((delta_s / 3600) % 3600)
if h > 0:
timer_show = f"{h}h {m}m {s}s"
elif m > 0:
timer_show = f"{m}m {s}s"
elif s > 0:
timer_show = f"{s}s"
print(
f"Looping through {wallpaper_count} wallpapers every {timer_show}")
while True:
if is_locked() != True:
random_int = random.randint(0, wallpaper_count-1)
wallpaper_now = wallapapers[random_int]
setwallpaper(wallpaper_now, plugin)
if lock_screen == True:
set_lockscreen_wallpaper(wallpaper_now, plugin)
time.sleep(timer)
else:
raise ValueError('Invalid --timer value')


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='KDE Wallpaper setter')
parser.add_argument('--file','-f', help='Wallpaper file name', default=None)
parser.add_argument(
'--plugin', '-p', help='Wallpaper plugin (default is org.kde.image)', default='org.kde.image')
parser.add_argument('--dir', '-d', type=str,
help='Absolute path of folder containging your wallpapers for slideshow', default=None)
parser.add_argument('--timer', '-t', type=int,
help='Time in seconds between wallpapers', default=900)
parser.add_argument('--lock-screen', '-l', action="store_true",
help="Set lock screen wallpaper")
args = parser.parse_args()

if args.file != None:
setwallpaper(filepath=args.file, plugin=args.plugin)
if args.lock_screen == True:
set_lockscreen_wallpaper(filepath=args.file, plugin=args.plugin)

elif args.dir != None:
wallpapers = get_walls_from_folder(args.dir)

wallpaper_slideshow(wallapapers=wallpapers,
plugin=args.plugin, timer=args.timer,lock_screen=args.lock_screen)
else:
print("Need help? use -h or --help")
2 changes: 1 addition & 1 deletion spotlight.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ After=network-online.target graphical-session.target

[Service]
Type=simple
ExecStart=/usr/bin/env bash spotlight.sh
ExecStart=/usr/bin/env bash -c ~/.local/bin/spotlight.sh
23 changes: 19 additions & 4 deletions spotlight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ then
exit 1
fi

gsettings set org.gnome.desktop.background picture-options "zoom"
gsettings set org.gnome.desktop.background picture-uri "file://$imagePath"
gsettings set org.gnome.desktop.background picture-uri-dark "file://$imagePath"
# KDE
if [ "$XDG_CURRENT_DESKTOP" == "KDE" ]; then
#echo "Assuming KDE."
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
python3 $SCRIPT_DIR/ksetwallpaper.py --file "$imagePath"
else
# Gnome:
#echo "Assuming Gnome."
gsettings set org.gnome.desktop.background picture-options "zoom"
gsettings set org.gnome.desktop.background picture-uri "file://$imagePath"
gsettings set org.gnome.desktop.background picture-uri-dark "file://$imagePath"
fi

mkdir -p "$spotlightPath"

Expand All @@ -81,5 +90,11 @@ then
rm "$previousImagePath"
fi

notify-send "Background changed" "$title ($searchTerms)" --icon=preferences-desktop-wallpaper --urgency=low --hint=string:desktop-entry:spotlight
# KDE:
if [ "$XDG_CURRENT_DESKTOP" == "KDE" ]; then
kdialog --passivepopup "$title ($searchTerms)" 10 --title "Background changed"
else
# Gnome
notify-send "Background changed" "$title ($searchTerms)" --icon=preferences-desktop-wallpaper --urgency=low --hint=string:desktop-entry:spotlight
fi
systemd-cat -t spotlight -p info <<< "Background changed to $title ($searchTerms)"