diff options
author | Andinus <andinus@nand.sh> | 2020-03-24 18:35:27 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-03-24 18:35:27 +0530 |
commit | bf040f6d1c8c7bc33d5268db42bc2ac9016e2198 (patch) | |
tree | 76006187821bd925a1509af614e4cecbef449133 /background/set_darwin.go | |
parent | 842bc9065905e8fcbd0e801526306407ac6793c4 (diff) | |
download | cetus-bf040f6d1c8c7bc33d5268db42bc2ac9016e2198.tar.gz |
Add background package
This rewrite has better comments and returns better error messages.
Diffstat (limited to 'background/set_darwin.go')
-rw-r--r-- | background/set_darwin.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/background/set_darwin.go b/background/set_darwin.go new file mode 100644 index 0000000..43e86b7 --- /dev/null +++ b/background/set_darwin.go @@ -0,0 +1,25 @@ +// +build darwin + +package background + +import ( + "fmt" + "os/exec" + "strconv" +) + +// SetFromFile takes a string as an input, it must be absolute path to +// the background. Checks are not made to check if the path exists or +// it is actually an image, that must be verified before passing it to +// SetFromFile. SetFromFile will exit returning in error if there is +// any. +func SetFromFile(path string) error { + err := exec.Command("osascript", "-e", + `tell application "System Events" to tell every desktop to set picture to `+strconv.Quote(path)).Run() + if err != nil { + err = fmt.Errorf("%s\n%s", + "set_darwin.go: failed to set background", + err.Error()) + } + return err +} |