sc is a tool to take a screencapture every x seconds https://godoc.org/git.zxq.co/howl/sc

screenshot.go 511B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "errors"
  4. "os/exec"
  5. "strings"
  6. )
  7. func takeScreenshot(saveTo string) error {
  8. if saveTo == "" {
  9. return errors.New("makeScreenshot: saveTo is empty string")
  10. }
  11. cmd := exec.Command("spectacle", "-b", "-n", "-o", saveTo)
  12. data, err := cmd.CombinedOutput()
  13. if err != nil {
  14. return err
  15. }
  16. // no news is good news.
  17. // if there are news, it's always bad news!
  18. rough := strings.Trim(string(data), "\n\t ")
  19. if len(rough) > 0 {
  20. return errors.New("spectacle: " + rough)
  21. }
  22. return nil
  23. }