Skip to content

Instantly share code, notes, and snippets.

@cauefcr
Last active July 29, 2019 22:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cauefcr/7e9f6b7d03b65b59d0cc0fd45a470c44 to your computer and use it in GitHub Desktop.
Save cauefcr/7e9f6b7d03b65b59d0cc0fd45a470c44 to your computer and use it in GitHub Desktop.
sets the input url as wallpaper every x seconds
package main
import (
"fmt"
"image"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/reujab/wallpaper"
sshot "github.com/slotix/pageres-go-wrapper"
ss "github.com/vova616/screenshot"
)
func main() {
if len(os.Args) < 3 {
fmt.Println("usage: ./webpaper website update_time_in_seconds")
return
}
t, err := strconv.Atoi(os.Args[2])
if err != nil {
log.Fatal(err)
}
img, err := ss.CaptureScreen()
myImg := image.Image(img)
b := myImg.Bounds().Max
for {
params := sshot.Parameters{
Command: "pageres",
Sizes: fmt.Sprintf("%vx%v", b.X, b.Y),
Crop: "--crop",
Scale: "--scale 1",
Timeout: "--timeout 30",
Filename: "--filename=sds",
UserAgent: "",
}
urls := []string{
os.Args[1],
}
sshot.GetShots(urls, params)
file := "sds.png"
ex, err := os.Executable()
if err != nil {
fmt.Println("w")
panic(err)
}
exPath := filepath.Dir(ex)
file = strings.Replace(exPath, "\\", "/", -1) + "/" + file
// Path to image.
wallpaper.SetFromFile(file)
fmt.Println(file)
time.Sleep(time.Second * time.Duration(t))
os.Remove(file)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment