launchservices

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package launchservices provides pure Go bindings for the macOS LaunchServices private SPI _LSOpenURLsWithCompletionHandler, the same function that /usr/bin/open uses internally. No cgo required.

It exposes a minimal API for launching applications and opening files/URLs via LaunchServices, with support for environment variables, I/O redirection, architecture selection, and process wait.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppURLFromBundleID

func AppURLFromBundleID(bundleID string) (objc.ID, error)

AppURLFromBundleID finds the file URL of an application by bundle identifier.

func AppURLFromName

func AppURLFromName(name string) (objc.ID, error)

AppURLFromName finds the file URL of an application by display name using NSWorkspace.

func DefaultAppForFile

func DefaultAppForFile(path string) (objc.ID, error)

DefaultAppForFile returns the default application URL for a given file path.

func DefaultTextEditorURL

func DefaultTextEditorURL() (objc.ID, error)

DefaultTextEditorURL returns the URL of the default text editor.

func URLPath

func URLPath(url objc.ID) string

URLPath extracts the filesystem path from an NSURL (calls -[NSURL path]).

func WaitForExit

func WaitForExit(pid int) error

WaitForExit uses kqueue/kevent to block until the given process exits. This is the same mechanism /usr/bin/open uses for -W (--wait-apps).

func WaitForExitMultiple

func WaitForExitMultiple(pids []int) error

WaitForExitMultiple uses kqueue/kevent to block until all given processes exit.

Types

type Options

type Options struct {
	// Activate brings the application to the foreground. Default true.
	Activate bool
	// Hide launches the application hidden.
	Hide bool
	// NewInstance launches a new instance even if one is already running.
	NewInstance bool
	// Fresh launches without restoring windows from previous session.
	Fresh bool
	// WaitForCheckIn tells LaunchServices to wait for the app to check in.
	WaitForCheckIn bool
	// Arguments are passed to the application as command-line arguments.
	Arguments []string
	// Environment is a map of environment variables to set for the launched app.
	Environment map[string]string
	// StdinPath redirects the launched app's stdin to this file path.
	StdinPath string
	// StdoutPath redirects the launched app's stdout to this file path.
	StdoutPath string
	// StderrPath redirects the launched app's stderr to this file path.
	StderrPath string
	// Arch specifies the CPU architecture to launch under (e.g., "arm64", "x86_64").
	Arch string
	// AddToRecents controls whether the opened item appears in Recents. Default true.
	AddToRecents bool
}

Options controls how an application is launched.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns Options with sensible defaults.

type Result

type Result struct {
	// PID is the process ID of the launched application, or 0 if unavailable.
	PID int
	// AlreadyRunning is true if the application was already running.
	AlreadyRunning bool
}

Result contains information about a launched application.

func LaunchApp

func LaunchApp(appPath string, documents []string, opts Options) (Result, error)

LaunchApp launches an application by its bundle file path (e.g., "/Applications/Safari.app"). Pass nil documents to launch the app without opening any files.

func LaunchBundleID

func LaunchBundleID(bundleID string, documents []string, opts Options) (Result, error)

LaunchBundleID launches an application by its bundle identifier (e.g., "com.apple.Safari").

func OpenDocuments

func OpenDocuments(files []string, appPath string, opts Options) (Result, error)

OpenDocuments opens files with the default application for each file type. An explicit appPath may be provided to override the default; pass "" to auto-resolve.

func OpenURL

func OpenURL(urlStr string, appPath string, opts Options) (Result, error)

OpenURL opens a URL string with the default or specified application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL