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 ¶
- func AppURLFromBundleID(bundleID string) (objc.ID, error)
- func AppURLFromName(name string) (objc.ID, error)
- func DefaultAppForFile(path string) (objc.ID, error)
- func DefaultTextEditorURL() (objc.ID, error)
- func URLPath(url objc.ID) string
- func WaitForExit(pid int) error
- func WaitForExitMultiple(pids []int) error
- type Options
- type Result
- func LaunchApp(appPath string, documents []string, opts Options) (Result, error)
- func LaunchBundleID(bundleID string, documents []string, opts Options) (Result, error)
- func OpenDocuments(files []string, appPath string, opts Options) (Result, error)
- func OpenURL(urlStr string, appPath string, opts Options) (Result, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppURLFromBundleID ¶
AppURLFromBundleID finds the file URL of an application by bundle identifier.
func AppURLFromName ¶
AppURLFromName finds the file URL of an application by display name using NSWorkspace.
func DefaultAppForFile ¶
DefaultAppForFile returns the default application URL for a given file path.
func DefaultTextEditorURL ¶
DefaultTextEditorURL returns the URL of the default text editor.
func WaitForExit ¶
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 ¶
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 ¶
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 ¶
LaunchBundleID launches an application by its bundle identifier (e.g., "com.apple.Safari").
func OpenDocuments ¶
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.