Skip to content

Instantly share code, notes, and snippets.

@xplato
Created August 8, 2023 16:08
Show Gist options
  • Save xplato/ff85973647e9a1b5190361e331c27fe0 to your computer and use it in GitHub Desktop.
Save xplato/ff85973647e9a1b5190361e331c27fe0 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"github.com/arduino/go-paths-helper"
log "github.com/sirupsen/logrus"
)
func GetDefaultHomeDir() *paths.Path {
// UserHomeDir returns the current user's home directory.
// On Unix, including macOS, it returns the $HOME environment variable.
// On Windows, it returns %USERPROFILE%.
// On Plan 9, it returns the $home environment variable.
homeDir, err := os.UserHomeDir()
if err != nil {
log.Panicf("Can't get user home dir: %s", err)
}
return paths.New(homeDir)
}
func getLaunchdAgentPath() *paths.Path {
homeDir := GetDefaultHomeDir()
launchAgentsPath := homeDir.Join("Library", "LaunchAgents")
agentPlistPath := launchAgentsPath.Join("ArduinoCreateAgent.plist")
if err := os.MkdirAll(launchAgentsPath.String(), 0755); err != nil {
log.Panicf("Could not create ~/Library/LaunchAgents directory: %s", err)
}
return agentPlistPath
}
func main() {
agentPlistPath := getLaunchdAgentPath()
log.Infof("Agent plist path: %s", agentPlistPath)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment