-
Notifications
You must be signed in to change notification settings - Fork 1
/
anybar.go
44 lines (37 loc) · 1.09 KB
/
anybar.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
// Package anybar provides an interface for the AnyBar OS X menubar app:
// https://github.com/tonsky/AnyBar
package anybar
import (
"fmt"
"net"
)
const DefaultPort = 1738
func Black() { _ = Send("black") }
func Blue() { _ = Send("blue") }
func Cyan() { _ = Send("cyan") }
func Green() { _ = Send("green") }
func Orange() { _ = Send("orange") }
func Purple() { _ = Send("purple") }
func Red() { _ = Send("red") }
func White() { _ = Send("white") }
func Yellow() { _ = Send("yellow") }
func Question() { _ = Send("question") }
func Exclamation() { _ = Send("exclamation") }
// Send sets the icon to the string given using the default AnyBar port
func Send(icon string) error {
return SendTo(icon, DefaultPort)
}
// SendTo sets the icon to the string given using a custom AnyBar port
func SendTo(icon string, port int) error {
address := fmt.Sprintf("localhost:%v", port)
conn, err := net.Dial("udp", address)
if err != nil {
return err
}
defer conn.Close()
_, err = conn.Write([]byte(icon))
if err != nil {
return err
}
return nil
}