desktopentry¶
Implements the freedesktop.org
Desktop Entry Specification —
the layer a dock, application menu or Spotlight-style finder needs: enumerate the
installed applications and expand their launch commands. Pure Go, CGO_ENABLED=0.
- Scan the standard XDG application directories for visible
.desktopentries. - Parse an entry:
Name,Icon,Exec,TryExec, categories, and actions. - Expand
Exec=into anargv, resolving field codes (%f,%U,%i, …) against the files you pass.
Install¶
Usage¶
package main
import (
"fmt"
"os/exec"
"github.com/go-freedesktop/desktopentry"
)
func main() {
// The launcher / Spotlight index: every visible installed app.
for _, e := range desktopentry.Scan() {
fmt.Printf("%-30s %s (icon: %s)\n", e.ID, e.Name, e.Icon)
}
// Launch one, opening a file.
e, _ := desktopentry.ParseFile("/usr/share/applications/org.gnome.gedit.desktop")
argv, err := e.ExpandExec([]string{"/tmp/notes.txt"}, "")
if err != nil {
panic(err)
}
_ = exec.Command(argv[0], argv[1:]...).Start()
// Offer an entry's actions ("New Window", …) — already parsed.
for _, a := range e.Actions {
fmt.Println("action:", a.Name, "→", a.Exec)
}
}
The full API is on pkg.go.dev. Source: github.com/go-freedesktop/desktopentry.