Advertisement
vonschutter

Untitled

Nov 12th, 2022
1,347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.64 KB | None | 0 0
  1. rtd_oem_kde_set_wallpaper ()
  2. {
  3. # Description:
  4. # Function to set KDE Plasma wallpaper from a script. this function expects one variable
  5. # indication what file to set as background. You must provide the full path to the file.
  6. # rtd_oem_kde_set_wallpaper /opt/oem/wallpaper.png Supported fule types are:
  7. # webm, mp4, png, jpeg, gif, webp.
  8. # Globals:
  9. # Arguments: None
  10. # Outputs:
  11. # Returns:
  12. # Usage:
  13. # End of documentation
  14.  
  15.     echo "Setting wallpaper $1"
  16.     full_image_path=$(realpath "$1")
  17.     ext=$(file -b --mime-type "$full_image_path")
  18.  
  19.     if [ -z "$2" ]; then
  20.     # Identify filetype and make changes
  21.     case $(echo $ext | cut -d'/' -f2) in
  22.         "mp4"|"webm") type='VideoWallpaper' ; write='VideoWallpaperBackgroundVideo';;
  23.         "png"|"jpeg"|"jpg") type='org.kde.image' ; write='Image' ;;
  24.         "gif"|"webp") type='GifWallpaper' ; write="GifWallpaperBackgroundGif" ;;
  25.     esac
  26.     else
  27.     type="$2";
  28.     write="$3";
  29.     fi
  30.  
  31.     wallpaper_set_script="var allDesktops = desktops();
  32.     print (allDesktops);
  33.     for (i=0;i<allDesktops.length;i++)
  34.     {
  35.         d = allDesktops[i];
  36.         d.wallpaperPlugin = '${type}';
  37.         d.currentConfigGroup = Array('Wallpaper', '${type}', 'General');
  38.         d.writeConfig('Image', 'file:///dev/null')
  39.         d.writeConfig('$write', 'file://${full_image_path}')
  40.     }"
  41.  
  42.     # have to put in these stupid fixes because distros can't agree where to but stuff!
  43.     hash qdbus || ${_qdbus="$(/usr/bin/qdbus-qt5)"} && ${_qdbus="qdbus"}
  44.     ${_qdbus} org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "${wallpaper_set_script}"
  45.     kwriteconfig5 --file kscreenlockerrc --group Greeter --group Wallpaper --group org.kde.image --group General --key Image "file://$full_image_path"
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement