toggle-tvtime 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env guile
  2. !#
  3. ;;; toggle-tvtime.scm --- Start or kill tvtime
  4. ;; Copyright © 2016 Alex Kost
  5. ;; Author: Alex Kost <alezost@gmail.com>
  6. ;; Created: 20 Mar 2016
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This script is used to start (with some additional preparations) or
  19. ;; kill 'tvtime' if it is already started.
  20. ;;; Code:
  21. (use-modules
  22. (ice-9 match)
  23. (al display)
  24. (al processes))
  25. (define (show-help)
  26. (format #t "Usage: ~a [ARGS ...]
  27. Start tvtime or kill it if already running.
  28. ARGS are arguments passed to tvtime.
  29. "
  30. (car (command-line))))
  31. (define (run-tvtime)
  32. (if (getenv "DISPLAY")
  33. (system* "tvtime")
  34. (with-display (first-used-display 3)
  35. (system* "tvtime"))))
  36. (define (main args)
  37. (match (cdr args)
  38. (((or "-h" "--help" "help") _ ...)
  39. (show-help))
  40. ((args ...)
  41. (if (process-exists? "tvtime" #:uid (getuid) #:exact? #t)
  42. (system* "tvtime-command" "QUIT")
  43. (run-tvtime)))))
  44. (when (batch-mode?)
  45. (main (command-line)))
  46. ;;; toggle-tvtime.scm ends here