Command line client for Write.as https://write.as/apps/cli
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
908 B

  1. // Copyright 2013 @atotto. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build darwin
  5. package clipboard
  6. import (
  7. "os/exec"
  8. )
  9. var (
  10. pasteCmdArgs = "pbpaste"
  11. copyCmdArgs = "pbcopy"
  12. )
  13. func getPasteCommand() *exec.Cmd {
  14. return exec.Command(pasteCmdArgs)
  15. }
  16. func getCopyCommand() *exec.Cmd {
  17. return exec.Command(copyCmdArgs)
  18. }
  19. func readAll() (string, error) {
  20. pasteCmd := getPasteCommand()
  21. out, err := pasteCmd.Output()
  22. if err != nil {
  23. return "", err
  24. }
  25. return string(out), nil
  26. }
  27. func writeAll(text string) error {
  28. copyCmd := getCopyCommand()
  29. in, err := copyCmd.StdinPipe()
  30. if err != nil {
  31. return err
  32. }
  33. if err := copyCmd.Start(); err != nil {
  34. return err
  35. }
  36. if _, err := in.Write([]byte(text)); err != nil {
  37. return err
  38. }
  39. if err := in.Close(); err != nil {
  40. return err
  41. }
  42. return copyCmd.Wait()
  43. }