Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "io/ioutil"
- "log"
- "time"
- "math/rand"
- "os/exec"
- )
- const (
- DCONF_PATH = "/org/mate/desktop/background/picture-filename"
- PICS_PATH = "/home/anon/Pictures/"
- DURATION_MIN = 10
- )
- func main() {
- rand.Seed(time.Now().UTC().UnixNano())
- changeBackground(getAllPictures())
- }
- func changeBackground(pictures []string) {
- for true {
- pos := rand.Intn(len(pictures))
- dconf_params := fmt.Sprintf("dconf write %s \"'%s/%s'\"", DCONF_PATH, PICS_PATH, pictures[pos])
- cmd := exec.Command("bash", "-c", dconf_params)
- cmd.Run()
- time.Sleep(DURATION_MIN * time.Minute)
- pictures = getAllPictures()
- }
- }
- func getAllPictures() []string {
- var pics []string
- files, err := ioutil.ReadDir(PICS_PATH)
- if err != nil {
- log.Fatal(err)
- }
- for _, file := range files {
- pics = append(pics, file.Name())
- }
- return pics
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement