Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.88 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"  
  5.     "io/ioutil"
  6.     "log"
  7.     "time"
  8.     "math/rand"
  9.     "os/exec"
  10. )
  11.  
  12. const (
  13.     DCONF_PATH   = "/org/mate/desktop/background/picture-filename"
  14.     PICS_PATH    = "/home/anon/Pictures/"
  15.     DURATION_MIN = 10
  16. )
  17.  
  18. func main() {
  19.     rand.Seed(time.Now().UTC().UnixNano())
  20.     changeBackground(getAllPictures())
  21. }
  22.  
  23. func changeBackground(pictures []string) {
  24.     for true {
  25.         pos := rand.Intn(len(pictures))
  26.         dconf_params := fmt.Sprintf("dconf write %s \"'%s/%s'\"", DCONF_PATH, PICS_PATH, pictures[pos])
  27.  
  28.         cmd := exec.Command("bash", "-c", dconf_params)
  29.         cmd.Run()
  30.  
  31.         time.Sleep(DURATION_MIN * time.Minute)
  32.         pictures = getAllPictures()
  33.     }
  34. }
  35.  
  36. func getAllPictures() []string {
  37.     var pics []string
  38.     files, err := ioutil.ReadDir(PICS_PATH)
  39.  
  40.     if err != nil {
  41.         log.Fatal(err)
  42.     }
  43.  
  44.     for _, file := range files {
  45.         pics = append(pics, file.Name())
  46.     }
  47.  
  48.     return pics
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement