Menu Close

ZSH/Bash reference stuff

xdotool: Commandline control of the mouse and keyboard functions.
Very good indepth man page for specifics and extra options…man xdotool

xdotool getmouselocation
#get the x, y co-ordinates and screen number and window info.
xdotool mousemove x y click 1
#move the mouse cursor to x,y position and left click (click 2 for rmb, click 3 for mmb).
xdotool mousemove x y click --repeat 2 1
#move cursor to x y location and double click with lmb (--repeat location is  important, needs to be after click but before button identifier!)
xdotool key --clearmodifiers x
#types the keyboard character 'x', see man page for --clearmodifiers, other options are clear etc. shift + a, ctrl + c.

Randomised selection within a script using ‘shuf’ command.
Very good man page for more info, man ‘shuf’.

sleep $(shuf -i 10-20 -n1)
#sleep for a random time between 10-20 seconds.

Taking info from a specified array within the script.

fruit=( "apple" "orange" "grape" "banana")
echo $(shuf -n1 -e "${fruit[@]}")
#Each echo command will randomly output one of the fruits.

Taking info from a file .

shuf -n1 filename
#take random entry from within the file if it's in the same folder as the script
shuf -n1 ~/folder/filename
#take random entry from with the file when it's in another location as specified.

Example script:

#Switches VPN server every hour.

#List of server locations.
servers=( "connect us" "connect uk" "connect fr" "connect es" "connect dk" "connect ca" )

#Connect to a random server from the array, wait 1 hour and connect to another random server from the array.
$(shuf -n1 -e "${servers[@]}")
sleep 3600