Last active
December 15, 2015 04:29
-
-
Save X4/5201986 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| WALLPAPER_PATH="$HOME/Bilder/Sample Pictures/" | |
| create_queue() { | |
| find $WALLPAPER_PATH -type f -iregex '.*\.\(jpg\|gif\|png\|jpeg\)$' > /tmp/krawall_queue | |
| } | |
| shuffle_wallpapers() { | |
| cat /tmp/krawall_queue | shuf -n 1 > /tmp/krawall_head | |
| } | |
| # shuffle wallpaper queue, or create it | |
| if [[ ! -f "/tmp/krawall_queue" ]] ; then | |
| create_queue | |
| else | |
| if [[( $1 == "--prev") || $1 == "-p" ]] ; then | |
| NEXT_WALLPAPER="$(cat /tmp/krawall_head 2>/dev/null)" | |
| fi | |
| if [[( $1 == "--next") || $1 == "-n" ]] ; then | |
| shuffle_wallpapers | |
| NEXT_WALLPAPER="$(cat /tmp/krawall_head 2>/dev/null)" | |
| fi | |
| if [[( $1 == "--resort") || $1 == "-r" ]] ; then | |
| shuffle_wallpapers | |
| echo -e "Successfully randomized the wallpaper list\n" | |
| exit 0 | |
| fi | |
| if [[( $1 == "--rescan") || $1 == "-s" ]] ; then | |
| rm -f /tmp/krawall_queue > /dev/null | |
| create_queue | |
| echo -e "Successfully created the wallpaper list\n" | |
| exit 0 | |
| fi | |
| fi | |
| # kde4 way... | |
| kde4_script=$(mktemp) && cat > $kde4_script \ | |
| <<_EOF | |
| var wallpaper = "$NEXT_WALLPAPER"; | |
| var activity = activities()[0]; | |
| activity.currentConfigGroup = ["Wallpaper","image"]; | |
| activity.writeConfig("wallpaper", wallpaper); | |
| activity.writeConfig("userswallpaper", wallpaper); | |
| activity.reloadConfig(); | |
| _EOF | |
| # Run the above javascript, then remove the temp file | |
| qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole $kde4_script > /dev/null && rm -f "$kde4_script" | |
| # Let's reparse the configuration | |
| dbus-send --dest=org.kde.plasma-desktop /MainApplication org.kde.plasma-desktop.reparseConfiguration | |
| dbus-send --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ReloadConfig | |
| dbus-send --dest=org.kde.kwin /KWin org.kde.KWin.reloadConfig | |
| # Run again to be sure, because I don't know what I do | |
| #qdbus org.kde.plasma-desktop /MainApplication reparseConfiguration | |
| #qdbus org.freedesktop.DBus /org/freedesktop/DBus ReloadConfig | |
| #qdbus org.kde.kwin /KWin reconfigure | |
| # This is stupid! I don't want to restart plasma, but have to? Isn't there a better way???????? | |
| kbuildsycoca4 2>/dev/null && kquitapp plasma-desktop 2>/dev/null ; kstart plasma-desktop > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment