It's a type of Planche
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  2. # homeassistant_access_token=""
  3. homeassistant_url="http://homeassistant.natrinicle.com:8123/api/states"
  4. homeassistant_screensaver_binary_sensor="${homeassistant_url}/binary_sensor.$(hostname | tr -s '-' '_' | tr '[:upper:]' '[:lower:]')_screen_locked"
  5. # MPRIS = Media Player Remote Interfacing Specification
  6. firefox_mpris_dbus=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -Po "org.mpris.*firefox[^\"]+")
  7. if [ -n "${firefox_mpris_dbus}" ]; then
  8. playback_string=$(dbus-send --print-reply --dest=${firefox_mpris_dbus} /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus' | grep -Po "(?<=string \")[^\"]+")
  9. fi
  10. # Suspend Firefox processes if not playing media
  11. if [ -z "${playback_string}" ] || [ "${playback_string}" != "Playing" ]; then
  12. ps aux | grep [f]irefox/[f]irefox | awk '{print $2}' | xargs -P0 -I {} kill -STOP {}
  13. fi
  14. # Suspend Atom processes
  15. ps aux | grep "/[a]tom" | awk '{print $2}' | xargs -P0 -I {} kill -STOP {}
  16. # Update Homeassistant
  17. if [ -n "${homeassistant_access_token}" ] && [ -n "${homeassistant_screensaver_binary_sensor}" ]; then
  18. curl -X POST -H "Authorization: Bearer ${homeassistant_access_token}" -H "Content-Type: application/json" -d "{\"state\": \"on\", \"attributes\": {\"friendly_name\": \"$(hostname) Screensaver\"}}" "${homeassistant_screensaver_binary_sensor}"
  19. fi