From a366be75f28a1dc50ebfd64cb71853614bb492ee Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 8 Apr 2021 17:23:17 +0100 Subject: [PATCH] Refactor (macos). --- internal/zenutil/osa_generated.go | 6 ++++-- internal/zenutil/osa_generator.go | 6 ++++-- internal/zenutil/run_darwin.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/zenutil/osa_generated.go b/internal/zenutil/osa_generated.go index 45022b0..4396954 100644 --- a/internal/zenutil/osa_generated.go +++ b/internal/zenutil/osa_generated.go @@ -3,8 +3,10 @@ package zenutil -import "encoding/json" -import "text/template" +import ( + "encoding/json" + "text/template" +) var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) { b, err := json.Marshal(v) diff --git a/internal/zenutil/osa_generator.go b/internal/zenutil/osa_generator.go index 6e3f2e4..0270174 100644 --- a/internal/zenutil/osa_generator.go +++ b/internal/zenutil/osa_generator.go @@ -100,8 +100,10 @@ var generator = template.Must(template.New("").Parse(`// Code generated by zenit package zenutil -import "encoding/json" -import "text/template" +import ( + "encoding/json" + "text/template" +) var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) { b, err := json.Marshal(v) diff --git a/internal/zenutil/run_darwin.go b/internal/zenutil/run_darwin.go index 29ef823..80c862e 100644 --- a/internal/zenutil/run_darwin.go +++ b/internal/zenutil/run_darwin.go @@ -23,9 +23,9 @@ func Run(ctx context.Context, script string, data interface{}) ([]byte, error) { // Try to use syscall.Exec, fallback to exec.Command. if path, err := exec.LookPath("osascript"); err != nil { } else if t, err := ioutil.TempFile("", ""); err != nil { + } else if err := os.Remove(t.Name()); err != nil { } else if _, err := t.WriteString(script); err != nil { } else if _, err := t.Seek(0, 0); err != nil { - } else if err := os.Remove(t.Name()); err != nil { } else if err := syscall.Dup2(int(t.Fd()), syscall.Stdin); err != nil { } else if err := os.Stderr.Close(); err != nil { } else {