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.

63 lines
1.1 KiB

  1. #!/usr/bin/env bash
  2. usage () {
  3. cat <<EOF
  4. Usage: lock [-s] [-d] [-a]
  5. -s : mute sound
  6. -d, : sleep display
  7. -a, : mute the sound and sleep the display
  8. -h, : print out usage info
  9. EOF
  10. }
  11. silence () {
  12. # mutes all audio
  13. if [[ $BOTH_OFF = true ]] || [[ $SOUND_OFF = true ]] ; then
  14. echo "Muting sound..."
  15. osascript -e "set Volume 0"
  16. fi
  17. }
  18. rest () {
  19. # sleeps the display
  20. if [[ $BOTH_OFF = true ]] || [[ $DISPLAY_OFF = true ]] ; then
  21. echo "Sleeping display..."
  22. open -a ScreenSaverEngine
  23. fi
  24. }
  25. both() {
  26. silence && rest
  27. }
  28. BOTH_OFF=false
  29. DISPLAY_OFF=false
  30. SOUND_OFF=false
  31. for i in "$@"
  32. do
  33. case $i in
  34. -h)
  35. usage
  36. exit 1
  37. ;;
  38. -a)
  39. BOTH_OFF=true
  40. both
  41. ;;
  42. -d)
  43. DISPLAY_OFF=true
  44. rest
  45. ;;
  46. -s)
  47. SOUND_OFF=true
  48. silence
  49. ;;
  50. *)
  51. usage
  52. exit 1
  53. ;;
  54. esac
  55. done
  56. exit 0