forked from go-ole/go-ole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itunes.go
47 lines (42 loc) · 968 Bytes
/
itunes.go
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
37
38
39
40
41
42
43
44
45
46
47
// +build windows
package main
import (
"log"
"os"
"strings"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
"github.com/gonuts/commander"
)
func iTunes() *ole.IDispatch {
ole.CoInitialize(0)
unknown, err := oleutil.CreateObject("iTunes.Application")
if err != nil {
log.Fatal(err)
}
itunes, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
log.Fatal(err)
}
return itunes
}
func main() {
command := &commander.Command{
UsageLine: os.Args[0],
Short: "itunes cmd",
}
command.Subcommands = []*commander.Command{}
for _, name := range []string{"Play", "Stop", "Pause", "Quit"} {
command.Subcommands = append(command.Subcommands, &commander.Command{
Run: func(cmd *commander.Command, args []string) error {
_, err := oleutil.CallMethod(iTunes(), name)
return err
},
UsageLine: strings.ToLower(name),
})
}
err := command.Dispatch(os.Args[1:])
if err != nil {
log.Fatal(err)
}
}