Advertisement
woohoo

Show notification when workspace changes for XFCE

Jul 10th, 2023 (edited)
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #!/bin/bash
  2. # Description: Show notification when workspace changes
  3. # Requires: awk, xfce4-notifyd, libnotify, wmctrl, trap
  4.  
  5. exitStatusSuccess=0
  6. exitStatusFail=1
  7. scriptname=$(basename -- "$0")
  8. scriptname="${scriptname%.*}"
  9. thisScriptFull=$(readlink -f ${BASH_SOURCE[0]})
  10. thisScriptPathOnly=$(dirname ${thisScriptFull})
  11.  
  12. # make sure that only one instance of this script is running per user
  13. lockfile=/tmp/.${scriptname}.$USER.lockfile
  14. if ( set -o noclobber; echo "locked" > "$lockfile" ) 2> /dev/null; then
  15.   trap 'rm -f "${lockfile}"; exit $?' INT TERM EXIT
  16.   echo "${scriptname} DEBUG: Locking succeeded" >&2
  17.  
  18.   sleep 3
  19.   WKS_NUMBER=$(wmctrl -d | awk -v val='*' '$2==val{print $1}')
  20.  
  21.   while true
  22.   do
  23.     WKS_NUMBER_NEW=$(wmctrl -d | awk -v val='*' '$2==val{print $1}')
  24.     if [ ${WKS_NUMBER} -ne ${WKS_NUMBER_NEW} ]; then
  25.       WKS_NUMBER=${WKS_NUMBER_NEW}
  26.       WKS_NAME=$(wmctrl -d | awk -v val='*' '$2==val{print $10}')
  27.       NUM_DISPLAY=$(( ${WKS_NUMBER} + 1 ))
  28.       notify-send -t 2000 -i cs-workspaces "Workspace Changed" "Workspace changed to \"${WKS_NAME}\" [${NUM_DISPLAY}]"
  29.     fi
  30.     sleep 0.5
  31.   done
  32.  
  33. # can't create lockfile - notify user and quit
  34. else
  35.   echo "${scriptname} DEBUG: Lock failed, check for existing process and/or lock file and delete exiting: ${lockfile}." >&2
  36.   exit ${exitStatusFail}
  37. fi
  38.  
  39. exit ${exitStatusSuccess}
  40.  
Tags: xfce bash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement