fork download
  1. #!/bin/bash
  2.  
  3. # Name: xfconfMonitor
  4. # Descrition: Monitors changes in xfce-configuation and outputs commands to
  5. # manually make the changes via command line.
  6. #
  7. # Not thread safe, but shouldn't need to be.
  8.  
  9. pids=()
  10.  
  11. function killallChildren()
  12. {
  13. for pid in "${pids[@]}"; do
  14. kill -15 "${pid}"
  15. done
  16. }
  17.  
  18. function listChannels()
  19. {
  20. readarray -t channels < <(xfconf-query -l | grep -v "^Channels:$")
  21.  
  22. for channel in "${channels[@]}"; do
  23. echo "${channel##* }"
  24. done
  25. }
  26.  
  27. function monitorChannel()
  28. {
  29. local channelToMonitor="${1}"
  30. while read -r line; do
  31. # First line from monitor is always:
  32. # Start monitoring channel "${channelToMonitor}":
  33. #Subsequent lines from monitor are always
  34. # set: ${changedProperty}
  35. #
  36. #So, we can just look at last token of each line.
  37. changedProperty="${line##* }"
  38. if [[ "${changedProperty}" == "\"${channelToMonitor}\":" ]] ; then
  39. #Ignore the "Start monitoring channel" line.
  40. continue
  41. fi
  42.  
  43. displayProperty "${channelToMonitor}" "${changedProperty}"
  44. done < <(xfconf-query -m -c "${channelToMonitor}")
  45. }
  46.  
  47. function displayProperty()
  48. {
  49. local channelToMonitor="${1}"
  50. local propertyToMonitor="${2}"
  51. if [[ "${channelToMonitor}" == "" ]] || [[ "${propertyToMonitor}" == "" ]]; then
  52. return
  53. fi
  54. #shellcheck disable=SC2155 #Ignoring return value. We will display any std output given whether command succeeds or fails.
  55. local value="$(xfconf-query -c "${channelToMonitor?}" -p "${changedProperty?}")"
  56.  
  57. #We are ignoring type for now.
  58. echo "xfconf-query --channel ${channelToMonitor} --property ${propertyToMonitor} --set ${value}"
  59. }
  60.  
  61. readarray -t channels < <(listChannels)
  62.  
  63. for channel in "${channels[@]}"; do
  64. monitorChannel "${channel}" 2> /dev/null &
  65. pids+=(${!})
  66. done
  67.  
  68. echo "Any changes made to xfce settings though the gui will be logged here."
  69. echo "When finished, simply press [ENTER] to quit"
  70.  
  71. read -r
  72. killallChildren
  73.  
  74.  
  75.  
  76.  
Success #stdin #stdout #stderr 0.01s 5284KB
stdin
Standard input is empty
stdout
Any changes made to xfce settings though the gui will be logged here.
When finished, simply press [ENTER] to quit
stderr
./prog.sh: line 16: xfconf-query: command not found