Advertisement
mosaid

Untitled

Jun 22nd, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.37 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: root\""
  10. ws[2]="\"2: net\""
  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.     lastWorkSpace=$(cat ~/.i3/.ws )
  22.     WorkSpaceName=$(i3-msg -t get_workspaces | jq -c '.[] |select(.focused)|.name' )
  23.     for ((i=1;i<=10;i++)) ; do
  24.         if [[ "${ws[$i]}" == "$WorkSpaceName" ]] ; then
  25.             currentWorkSpace=$i
  26.             break
  27.         fi
  28.     done
  29.     if [[ "$lastWorkSpace" != "$currentWorkSpace" ]]  
  30.         then
  31.             echo "$currentWorkSpace" >| ~/.i3/.ws
  32.             if (($currentWorkSpace !=10 && "$lastWorkSpace" == 10 )) ; then
  33.                 #here something to do when you just open ws 10
  34.             fi
  35.             if (($currentWorkSpace!=10)) ; then
  36.                 # some personal stuff
  37.             fi
  38.             if (($currentWorkSpace==10)) ; then
  39.                 #other personal stuf,
  40.             fi
  41.             return "$currentWorkSpace"
  42.         else
  43.             return 0
  44.     fi
  45.     return 0
  46. }
  47. #this is the engine that keeps running
  48. # every second it gets the current ws
  49. # change wallpaper every 30 s
  50. # or the second the ws changes
  51.  
  52. ii=0
  53. while true ; do
  54.     getws
  55.     index=$?
  56.     if (($index != 0 || $ii >= 30 )) ; then
  57.         /home/mosaid/.i3/wchanger.sh
  58.         ii=0
  59.     fi
  60.     ii=$((ii+1))
  61.     sleep 1
  62. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement