在Linux没找到适合的壁纸软件,于是估摸着本人简略实现了一个。

  • 性能由三局部实现:

    bgwall 软件主体,由 ruby 编写的脚本。调度图片获取脚本,以及壁纸更换。
    ./fethch_script/ 寄存获取图片的脚本。
    ./post_script/ 寄存对获取后的图片进行前期加工的脚本。
  • 成果
  • 源码如下 (相当之简陋 勉强能用)

    #!/usr/bin/env ruby# encoding:utf-8# -*- coding: UTF-8 -*-require 'fileutils'# 壁纸更换距离DURA = 30 * 60IMGS = 2# 图片脚本调用形式 INDEX 程序; RANDOM 随机FETCH = 'INDEX'VALS = { :INDEX_FETCH => 0, :COUNT_FETCH => 0 }# 图片长期寄存门路IMG = '/tmp/bgwall/'FSC = './fetch_script/'PSC = './post_script/'CBG = "#{IMG}/bgwall_current.png"NBG = "#{IMG}/bgwall_next.png"def call_bg_script(script, img_dir, count)return nil if script.nil?file = `#{script[0]} #{img_dir}/#{script[1]}_#{count} #{count}`.chompputs ">>> bg [#{file}] fetch by #{script[1]}"return fileenddef call_post_script(img_path)Dir::open(PSC).filter{|f| f.start_with? /\d+/ and File.executable? PSC + f }.sort.map{|v| [PSC + v, v] }.each_with_index do |script,index|  nName = "#{IMG}#{index}_#{File.basename(img_path)}"  FileUtils.copy_file img_path, nName  system("#{script[0]} #{img_path} #{nName}")  img_path = nNameendreturn img_pathenddef get_background_image(fetch_type)VALS[:COUNT_FETCH] += 1fsca = Dir::open(FSC).filter{|f| f.start_with? /\d+/ and File.executable? FSC + f }.sort.map{|v| [FSC + v, v] }return nil if fsca.empty?call_bg_script case fetch_typewhen 'RANDOM'fsca[ rand fsca.size ]when 'INDEX'VALS[:INDEX_FETCH] += 1fsca[ VALS[:INDEX_FETCH] % fsca.size ]elsefsca[ rand fsca.size ]end, IMG, VALS[:COUNT_FETCH]enddef set_background_image(img_path)# 依据不同的环境 应用不同的 工具#system("hsetroot -fill #{img_path}")puts ">>> set background #{img_path} [#{Time.now}]\n\n"system("feh --bg-scale #{img_path}")end`[[ -d #{IMG} ]] || mkdir #{IMG}; echo $(date) > #{PSC}/start && echo $(date) > #{FSC}/start; sleep 2`# 每分钟刷新一次桌面背景 次要更新图片解决进本的操作,比方刷新显示工夫Thread::new doloop do  if Time.now.sec == 00    next if not File.exist? CBG    if File.exist? NBG      set_background_image NBG    else      set_background_image CBG    end    post_bg = call_post_script CBG    FileUtils.copy_file post_bg, NBG  end  sleep 1endend# 间隔时间后 拉取新壁纸loop dosleep 7 if Time.now.sec == 00file = get_background_image FETCHFileUtils.copy_file file, CBG if not file.nil?next if not File.exist? CBGsleep DURAend
  • 工夫脚本

    #!/usr/bin/env zsh# $1 源图片门路# $2 寄存门路_dz=("子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥")now=$(date "+%H")dz=$_dz[$[ ($now + 1) / 2 % 12 + 1]]"   時"now=$now":"$[ $(date "+%M") + 1]convert $1 -font Noteworthy-Bold.ttf -gravity SouthEast -pointsize 200 -fill white -annotate +100+100 "$now" $2convert $2 -font /usr/share/fonts/wps-office/FZLSK.TTF -gravity SouthEast -pointsize 200 -fill white -annotate +100+500 "$dz" $2
  • 拉取脚本

    #!/usr/bin/env zsh# $1 寄存门路# $2 以后脚本的调用次数base_page="https://wallhere.com/zh/wallpapers?q=狗&page=$2&pageSize=1&format=json"data_id=$(curl $base_page | jq .data | sed  -e 's/\\r\\n//g' -e 's/\\//g' | grep -Po '(?<=data-id=")(\d+?)(?=")' | head -n1)img_url="https://wallhere.com/zh/wallpaper/$data_id"img_src=$(curl $img_url | grep current-page-photo | grep -Po '(?<=href\=")(.*?)(?=")')wget $img_src -O $1.jpgecho $1.jpg

    或者

    #!/usr/bin/env zsh# $1 寄存门路# $2 以后脚本的调用次数echo "/home/user/Pictures/background.png"
  • 长处

    图片起源容易扩大,只有会一门语言,简略爬取就行
  • 已知问题

    刚运行时 不会设置图片,在失去图片后的下一分钟更新壁纸时才有。