https://github.com/stephen-fox/launchctlutil
A Go library that provides functionality for working with the launchctl application and launchd.
https://github.com/stephen-fox/launchctlutil
launchctl launchd macos
Last synced: 5 months ago
JSON representation
A Go library that provides functionality for working with the launchctl application and launchd.
- Host: GitHub
- URL: https://github.com/stephen-fox/launchctlutil
- Owner: stephen-fox
- License: mit
- Created: 2018-04-22T01:40:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-15T01:12:14.000Z (over 6 years ago)
- Last Synced: 2025-07-20T03:09:40.155Z (6 months ago)
- Topics: launchctl, launchd, macos
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# launchctlutil
A Go library that provides functionality for working with the launchctl
application and launchd.
## API
The library offers a basic API for interacting with launchd via launchctl.
This includes building configurations and installing them:
```go
package main
import (
"fmt"
"log"
"github.com/stephen-fox/launchctlutil"
)
func main() {
config, err := launchctlutil.NewConfigurationBuilder().
SetKind(launchctlutil.UserAgent).
SetLabel("com.testing").
SetRunAtLoad(true).
SetCommand("echo").
AddArgument("Hello world!").
SetLogParentPath("/tmp").
Build()
if err != nil {
log.Fatal(err.Error())
}
fmt.Println("Configuration contents:\n" + config.GetContents())
err = launchctlutil.Install(config)
if err != nil {
log.Fatal(err.Error())
}
// Remove by running:
// launchctl remove com.testing
// rm ~/Library/LaunchAgents/com.testing.plist
}
```
You can also get the status of an agent (or a daemon if running as `root`):
```go
package main
import (
"fmt"
"log"
"github.com/stephen-fox/launchctlutil"
)
func main() {
details, err := launchctlutil.CurrentStatus("com.apple.Dock.agent")
if err != nil {
log.Fatal(err.Error())
}
log.Println("Status:", details.Status)
if details.GotPid() {
log.Println("Current PID:", details.Pid)
}
if details.GotLastExitStatus() {
log.Println("Last exit status:", details.LastExitStatus)
}
}
```