package main import ( "fmt" "os" "os/exec" "sync" "time" "github.com/gen2brain/beeep" ) // Run will take the config file and for each task, run a go routine func TaskRun(c Config) { var wg sync.WaitGroup for i := range c.Tasks { title := c.Tasks[i].TaskName interval := c.Tasks[i].Interval var desc string // check if desc is empty and use the cmd output, if not just get the desc if c.Tasks[i].TaskDesc == "" { desc = TaskCMD(c.Tasks[i]) } else { desc = c.Tasks[i].TaskDesc } asset := c.Tasks[i].Icon //run the commands with go func()! wg.Add(1) go func() { fmt.Printf("%s has time interval %d\n", title, interval) for range time.Tick(time.Second * interval) { err := beeep.Notify(title, desc, asset) if err != nil { fmt.Fprintf(os.Stderr, "ERROR: could not display \"%s\":\n\t%s\n", title, err) } } wg.Done() }() } wg.Wait() } // TaskCMD will take in a Task, run the command with bash and return the string output func TaskCMD(t Task) (output string) { command := t.CMD if command == " " { fmt.Printf("INFO: Task %s has the cmd section empty. Will just return...\n", t.TaskName) return } out, err := exec.Command("bash", "-c", command).Output() if err != nil { fmt.Fprintf(os.Stderr, "ERROR: could not run command \"%s\":\n\t%s\n", command, err) } return string(out) }