2020-01-05 07:37:45 -05:00
|
|
|
package osa
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
"github.com/ncruces/zenity/internal/cmd"
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
res := buf.String()
|
2020-01-06 07:01:51 -05:00
|
|
|
res = res[len("<script>") : len(res)-len("\n</script>")]
|
2020-01-06 19:57:00 -05:00
|
|
|
|
|
|
|
if cmd.Command {
|
|
|
|
cmd, err := exec.LookPath("osascript")
|
|
|
|
if err == nil {
|
|
|
|
os.Stderr.Close()
|
|
|
|
syscall.Exec(cmd, []string{"osascript", "-l", "JavaScript", "-e", res}, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-05 07:37:45 -05:00
|
|
|
cmd := exec.Command("osascript", "-l", "JavaScript")
|
|
|
|
cmd.Stdin = strings.NewReader(res)
|
|
|
|
return cmd.Output()
|
|
|
|
}
|
|
|
|
|
|
|
|
type File struct {
|
|
|
|
Operation string
|
|
|
|
Prompt string
|
2020-01-06 07:01:51 -05:00
|
|
|
Name string
|
2020-01-05 07:37:45 -05:00
|
|
|
Location string
|
|
|
|
Type []string
|
|
|
|
Multiple bool
|
2020-01-06 07:01:51 -05:00
|
|
|
Separator rune
|
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
|
|
|
}
|