Advertisement
mosaid

Untitled

May 10th, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. scriptname=$( basename "$0" )
  3. is_running=$( pgrep -cf "$scriptname" )
  4. if (( $is_running > 1 )) ; then
  5.     >&2 echo $scriptname is running.
  6.     exit 0
  7. fi
  8. declare -A ws=()
  9. ws[1]="\"1: \""
  10. ws[2]="\"2: \""
  11. ws[3]="\"3: Media\""
  12. ws[4]="\"4: Files\""
  13. ws[5]="\"5: Work\""
  14. ws[6]="\"6: Docs\""
  15. ws[7]="\"7\""
  16. ws[8]="\"8\""
  17. ws[9]="\"9\""
  18. ws[10]="\"10\""
  19.  
  20. function getws () {
  21.     lastws=$(cat ~/.i3/.ws )
  22.     currentws=$(i3-msg -t get_workspaces | jq -c '.[] |select(.focused)|.name' )
  23.     if [[ "$lastws" != "$currentws" ]]  ; then
  24.         echo "$currentws" >| ~/.i3/.ws
  25.         for ((i=1;i<=10;i++)) ; do
  26.             if [[ "${ws[$i]}" == "$currentws" ]] ; then
  27.                 currentIndex=$i
  28.                 if (($currentIndex !=10)) && [[ "$lastws" == ${ws[10]} ]]
  29.                     then
  30.                         #some personal stuff
  31.                 fi
  32.                 return "$currentIndex"
  33.             fi
  34.         done
  35.     fi
  36.     return 0
  37. }
  38.  
  39. i=0
  40. while true ; do
  41.     getws
  42.     index=$?
  43.     if (($index != 0 || $i >= 30 )) ; then
  44.         if (($index !=0 )) ; then lasti=$index ; fi
  45.         $HOME/.i3/wchanger.sh $lasti  #script to change wallpaper if ws changed or 30s passed
  46.         i=0
  47.     fi
  48.     i=$((i+1))
  49.     sleep 1
  50. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement