Remove AppleScript.
This commit is contained in:
parent
dc342bfc5a
commit
6c0e609037
6 changed files with 26 additions and 24 deletions
|
@ -18,7 +18,11 @@ func selectColor(options []Option) (color.Color, error) {
|
|||
}
|
||||
r, g, b, _ := col.RGBA()
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, "color", []uint32{r, g, b})
|
||||
out, err := zenutil.Run(opts.ctx, "color", []float32{
|
||||
float32(r) / 0xffff,
|
||||
float32(g) / 0xffff,
|
||||
float32(b) / 0xffff,
|
||||
})
|
||||
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
6
go.sum
6
go.sum
|
@ -8,9 +8,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.uber.org/goleak v1.0.0 h1:qsup4IcBdlmsnGfqyLl4Ntn3C2XCCuKAE7DwHpScyUo=
|
||||
go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -38,6 +37,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
|
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -11,11 +11,13 @@ var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func
|
|||
return string(b), err
|
||||
}}).Parse(`
|
||||
{{define "color" -}}
|
||||
tell application "SystemUIServer"
|
||||
activate
|
||||
set c to choose color default color { {{index . 0}},{{index . 1}},{{index . 2}} }
|
||||
"rgb(" & (item 1 of c) div 256 & "," & (item 2 of c) div 256 & "," & (item 3 of c) div 256 & ")"
|
||||
end tell
|
||||
var app = Application.currentApplication()
|
||||
app.includeStandardAdditions = true
|
||||
app.activate()
|
||||
var opts = {}
|
||||
opts.defaultColor = {{json .}}
|
||||
var res = app.chooseColor(opts)
|
||||
'rgb(' + res.map(x => Math.round(x * 255)) + ')'
|
||||
{{- end}}
|
||||
{{define "file" -}}
|
||||
var app = Application.currentApplication()
|
||||
|
@ -90,7 +92,6 @@ void 0
|
|||
{{define "notify" -}}
|
||||
var app = Application.currentApplication()
|
||||
app.includeStandardAdditions = true
|
||||
app.activate()
|
||||
var opts = {}
|
||||
{{if .Title -}}
|
||||
opts.withTitle = {{json .Title}}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
tell application "SystemUIServer"
|
||||
activate
|
||||
set c to choose color default color { {{index . 0}},{{index . 1}},{{index . 2}} }
|
||||
"rgb(" & (item 1 of c) div 256 & "," & (item 2 of c) div 256 & "," & (item 3 of c) div 256 & ")"
|
||||
end tell
|
9
internal/zenutil/osascripts/color.gojs
Normal file
9
internal/zenutil/osascripts/color.gojs
Normal file
|
@ -0,0 +1,9 @@
|
|||
var app = Application.currentApplication()
|
||||
app.includeStandardAdditions = true
|
||||
app.activate()
|
||||
|
||||
var opts = {}
|
||||
opts.defaultColor = {{json .}}
|
||||
|
||||
var res = app.chooseColor(opts)
|
||||
'rgb(' + res.map(x => Math.round(x * 255)) + ')'
|
|
@ -18,21 +18,16 @@ func Run(ctx context.Context, script string, data interface{}) ([]byte, error) {
|
|||
}
|
||||
|
||||
script = buf.String()
|
||||
lang := "AppleScript"
|
||||
if strings.HasPrefix(script, "var app") {
|
||||
lang = "JavaScript"
|
||||
}
|
||||
|
||||
if Command {
|
||||
path, err := exec.LookPath("osascript")
|
||||
if err == nil {
|
||||
os.Stderr.Close()
|
||||
syscall.Exec(path, []string{"osascript", "-l", lang, "-e", script}, nil)
|
||||
syscall.Exec(path, []string{"osascript", "-l", "JavaScript", "-e", script}, nil)
|
||||
}
|
||||
}
|
||||
|
||||
if ctx != nil {
|
||||
cmd := exec.CommandContext(ctx, "osascript", "-l", lang)
|
||||
cmd := exec.CommandContext(ctx, "osascript", "-l", "JavaScript")
|
||||
cmd.Stdin = strings.NewReader(script)
|
||||
out, err := cmd.Output()
|
||||
if ctx.Err() != nil {
|
||||
|
@ -40,7 +35,7 @@ func Run(ctx context.Context, script string, data interface{}) ([]byte, error) {
|
|||
}
|
||||
return out, err
|
||||
}
|
||||
cmd := exec.Command("osascript", "-l", lang)
|
||||
cmd := exec.Command("osascript", "-l", "JavaScript")
|
||||
cmd.Stdin = strings.NewReader(script)
|
||||
return cmd.Output()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue