#!/bin/bash
# Name: xfconfMonitor
# Descrition: Monitors changes in xfce-configuation and outputs commands to
# manually make the changes via command line.
#
# Not thread safe, but shouldn't need to be.
pids=()
function killallChildren()
{
for pid in "${pids[@]}"; do
kill -15 "${pid}"
done
}
function listChannels()
{
readarray -t channels < <(xfconf-query -l | grep -v "^Channels:$")
for channel in "${channels[@]}"; do
echo "${channel##* }"
done
}
function monitorChannel()
{
local channelToMonitor="${1}"
while read -r line; do
# First line from monitor is always:
# Start monitoring channel "${channelToMonitor}":
#Subsequent lines from monitor are always
# set: ${changedProperty}
#
#So, we can just look at last token of each line.
changedProperty="${line##* }"
if [[ "${changedProperty}" == "\"${channelToMonitor}\":" ]] ; then
#Ignore the "Start monitoring channel" line.
continue
fi
displayProperty "${channelToMonitor}" "${changedProperty}"
done < <(xfconf-query -m -c "${channelToMonitor}")
}
function displayProperty()
{
local channelToMonitor="${1}"
local propertyToMonitor="${2}"
if [[ "${channelToMonitor}" == "" ]] || [[ "${propertyToMonitor}" == "" ]]; then
return
fi
#shellcheck disable=SC2155 #Ignoring return value. We will display any std output given whether command succeeds or fails.
local value="$(xfconf-query -c "${channelToMonitor?}" -p "${changedProperty?}")"
#We are ignoring type for now.
echo "xfconf-query --channel ${channelToMonitor} --property ${propertyToMonitor} --set ${value}"
}
readarray -t channels < <(listChannels)
for channel in "${channels[@]}"; do
monitorChannel "${channel}" 2> /dev/null &
pids+=(${!})
done
echo "Any changes made to xfce settings though the gui will be logged here."
echo "When finished, simply press [ENTER] to quit"
read -r
killallChildren