-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexec.go
More file actions
36 lines (30 loc) · 833 Bytes
/
exec.go
File metadata and controls
36 lines (30 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"bytes"
"errors"
"fmt"
"log"
"os/exec"
)
var errEndOfTabs = errors.New("end of tabs")
func execOsaScript(script string, stdout *bytes.Buffer, stderr *bytes.Buffer, verbose bool) error {
// There is no intention that this implementation be secure so ignore the linter warning
cmd := exec.Command("osascript", "-e", script) // #nosec
cmd.Stdout = stdout
cmd.Stderr = stderr
if verbose {
log.Printf("executing: %s\n", cmd.String())
}
if err := cmd.Run(); err != nil {
// Check stderr for clean exit on end-of-tabs error
if stderr.Len() == 0 || isEndOfTabsErrCode(stderr) {
if verbose {
log.Print("next tab of window 1 not found, end of tabs")
}
return errEndOfTabs
}
// Return error if not end-of-tabs
return fmt.Errorf("%s\n%v\n", stderr.String(), err)
}
return nil
}