Tiny macOS menubar utility for Go.
Adds a system tray icon with a "Quit" menu item and simple callbacks.
go get github.com/tetsuo/xtray
Requires macOS. Uses cgo
and the Cocoa framework.
package main
import (
"fmt"
"log"
"github.com/tetsuo/xtray"
)
func main() {
if err := xtray.Tray(
xtray.WithTooltip("MyApp"),
xtray.WithIcon("icon.pdf"),
xtray.WithLaunchCallback(func() {
fmt.Println("Launched!")
}),
xtray.WithQuitCallback(func() {
fmt.Println("Quitting...")
}),
); err != nil {
log.Fatal(err)
}
}
func Tray(opts ...Option) error
Launches the macOS menubar app and blocks until it is quit.
Option | Description |
---|---|
WithTooltip(string) |
Sets the tooltip shown on hover |
WithIcon(string) |
Path to a .pdf tray icon |
WithLaunchCallback(func()) |
Called after the app has finished launching |
WithQuitCallback(func()) |
Called before the app terminates |
MIT