xtray ๐Ÿงƒ

July 25, 2025 ยท View on GitHub

Tiny macOS menubar utility for Go.

screenshot

Adds a system tray icon with a "Quit" menu item and simple callbacks.

Install

go get github.com/tetsuo/xtray

Requires macOS. Uses cgo and the Cocoa framework.

Usage

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)
	}
}

API

func Tray(opts ...Option) error

Launches the macOS menubar app and blocks until it is quit.

Options

OptionDescription
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

License

MIT