summaryrefslogtreecommitdiff
path: root/get_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'get_darwin.go')
-rw-r--r--get_darwin.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/get_darwin.go b/get_darwin.go
index 39cbe0a..f2183a4 100644
--- a/get_darwin.go
+++ b/get_darwin.go
@@ -1,10 +1,9 @@
package hostname
-// functions to import and export the protobuf
-// data to and from config files
-
import (
- "os"
+ "bytes"
+ "fmt"
+ "os/exec"
)
// scutil --get HostName
@@ -13,6 +12,17 @@ import (
// scutil --set HostName my-mac.example.com
func osGetHostname() (string, error) {
- hostname, err := os.Hostname()
- return hostname, err
+ return scutil([]string{"-get", "HostName"})
+}
+
+// getDomainName executes the 'domainname' command and returns its output.
+func scutil(args []string) (string, error) {
+ cmd := exec.Command("scutil", args)
+ var out bytes.Buffer
+ cmd.Stdout = &out
+ if err := cmd.Run(); err != nil {
+ return "", fmt.Errorf("failed to execute 'scutil': %w", err)
+ }
+ domain := out.String()
+ return domain, nil
}