zenity/internal/zenutil/run_darwin.go

70 lines
1.1 KiB
Go
Raw Normal View History

2020-01-19 06:57:05 -05:00
package zenutil
2020-01-05 07:37:45 -05:00
import (
2020-01-06 19:57:00 -05:00
"os"
2020-01-05 07:37:45 -05:00
"os/exec"
"strings"
2020-01-06 19:57:00 -05:00
"syscall"
2020-01-05 07:37:45 -05:00
)
func Run(script string, data interface{}) ([]byte, error) {
var buf strings.Builder
err := scripts.ExecuteTemplate(&buf, script, data)
if err != nil {
return nil, err
}
2020-01-21 07:03:58 -05:00
script = buf.String()
lang := "AppleScript"
if strings.HasPrefix(script, "var app") {
lang = "JavaScript"
}
2020-01-06 19:57:00 -05:00
2020-01-19 06:57:05 -05:00
if Command {
2020-01-09 06:17:39 -05:00
path, err := exec.LookPath("osascript")
2020-01-06 19:57:00 -05:00
if err == nil {
os.Stderr.Close()
2020-01-21 07:03:58 -05:00
syscall.Exec(path, []string{"osascript", "-l", lang, "-e", script}, nil)
2020-01-06 19:57:00 -05:00
}
}
2020-01-21 07:03:58 -05:00
cmd := exec.Command("osascript", "-l", lang)
cmd.Stdin = strings.NewReader(script)
2020-01-05 07:37:45 -05:00
return cmd.Output()
}
type File struct {
2020-01-12 18:09:11 -05:00
Operation string
Prompt string
Name string
Location string
Separator string
Type []string
Invisibles bool
Multiple bool
2020-01-05 07:37:45 -05:00
}
2020-01-18 23:28:06 -05:00
type Color struct {
2020-01-21 11:13:45 -05:00
Color []uint16
2020-01-18 23:28:06 -05:00
}
2020-01-05 07:37:45 -05:00
type Msg struct {
2020-01-06 07:01:51 -05:00
Operation string
Text string
Message string
As string
Title string
Icon string
2020-01-06 19:57:00 -05:00
Extra string
2020-01-06 07:01:51 -05:00
Buttons []string
Cancel int
Default int
2020-01-05 07:37:45 -05:00
}
2020-01-26 11:04:49 -05:00
type Notify struct {
Text string
Title string
Subtitle string
}