This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Unlock desktop widgets from command line

Tags: None
(comma "," separated)
vkkodali
Registered Member
Posts
7
Karma
0
Greetings!
I am trying to use this ruby script (pasted below) to set my desktop wallpaper automatically and change it every day. The script works just fine as long as my desktop widgets are unlocked. I'd like to keep my desktop widgets locked, however. Can someone please add additional lines to unlock widgets first, change wallpaper, and then lock the widgets back again?

Code: Select all
require 'net/http'
require 'open-uri'
require 'json'
require 'optparse'
require 'tempfile'

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: #{__FILE__} [options]"

  opts.on('-nNUMBER', '--number=NUMBER', 'Image number from 1 to 9') do |n|
    options[:number] = n
  end

  opts.on("-h", "--help", "Prints this help") do
    puts opts
    exit
  end
end.parse!

number = options[:number] ? options[:number].match(/\A[1-9]{1}\z/) ? $&.to_i : 1 : 1
number -= 1

url = 'https://api.gopro.com/v2/channels/feed/playlists/photo-of-the-day.json?platform=web&page=1&per_page=9'

uri = URI(url)
response = Net::HTTP.get(uri)
data = JSON.parse(response)

image_url = data['media'][number]['thumbnails']['full']['image']
image_uri = URI(image_url)

image_file = Tempfile.new('gopro_wallpaper')

begin
  # Download image to tempfile
  File.open(image_file, "wb") do |f|
    open(image_url, "rb") do |read_file|
      f.write(read_file.read)
    end
  end

  # Set wallpaper
  set_wallpaper_script = %Q[
    var allDesktops = desktops();
    print (allDesktops);
    for (i=0; i<allDesktops.length; i++) {
      d = allDesktops[i];
      d.wallpaperPlugin = "org.kde.image";
      d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");
      d.writeConfig("Image", "file://#{image_file.path}")
    }
  ]

  %x[qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '#{set_wallpaper_script}']
  sleep 1
ensure
  image_file.close
end


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]