Monday, November 14, 2016

xfce4 background, and linux command line xml parse example





http://unix.stackexchange.com/questions/131238/where-is-the-current-wallpaper-stored


xml script example

#!/bin/bash -
# taken from
#  http://unix.stackexchange.com/questions/131238/where-is-the-current-wallpaper-stored
# must install xmllint
# /usr/bin/xmllint      libxml2-utils
#
# define xfce4 xml file that holds info about desktops 
# 
DESKTOP="/home/$(id -un)/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml"
#
# define xpath that will extract current desktop background file name
# (NB I am no expert in xpaths and there is probably a much more elegant way
#  to do this but this works for me)
#
XPATH='(//property[@name="workspace0"]/property[@name="last-image"])[last()]/@value'
#
# use xmllint utility to apply xpath to file and extract file path and name
#
IMAGE=$(xmllint --xpath "string(${XPATH})" "${DESKTOP}")
#
# display the file info extracted
#
echo Current Wallpaper File = ${IMAGE}
#
# rest of script........
#

xx

No comments:

Post a Comment