Viewing a single comment thread. View all comments

raddleboy OP wrote

<div>
#!/bin/bash
xdotool if_mouse_is_in_corner_then_exit
sleep 1
xdotool key super
sleep 1
xdotool type "text editor"
sleep 1
xdotool key Return
sleep 1
xdotool type "oire oiqerjh ;ouqrjbj erqvkhb nvurv hk erv kbrvbk qrvkh k qero;nq eruobqv kjqbviybqek vihbv sihfbv afvkhlaek vkhebvh khbk iubefvibo afkbajfipufv[  ounqnvfq v knv knqef viu;nqlv oqv qoubvekjvbkd vn zdfkj kjfvbfnkbffdn nv jdfjnfgjbnfjbfjskmcokpslcpljc jdnvnm ckenci,d kn"
</div>

This is the sample script. As you can see, i didn't quite understand how to apply the "if_mouse......._exit"

How do i make it stop by either moving my mouse into a corner or any other way.

3

nulloperation wrote (edited )

As you can see, i didn't quite understand how to apply the "if_mouse......._exit"

Well, that function doesn't exist yet, so the idea would be for you to write it.

How do i make it stop by either moving my mouse into a corner or any other way.

I'll give it a try. First explanation, then some code.

To tell whether the mouse is near the corner, we'll define a function mouse_near_corner. First we need to use xdotool getmouselocation to get the location of the mouse, and xdotool getdisplaygeometry to get the display geometry. (Unfortunately this output of getmouselocation is a bit verbose and inconsistent with the output getdisplaygeometry, so we have to massage the data a bit using "lookbehind" in grep, which matches "regular expressions", which may look a bit frightening.) Then we need to compare the mouse position to the display geometry to tell whether the mouse is near one of the four corners (if we're assuming there's just one screen). For convenience, we can define a function near which tells whether two numbers are closer than a given threshold (which I've set to 50 here).

(Another tricky bit is that return uses 0 for success and 1 for failure, while expr uses 1 for true and 0 for false, so the comparison has to be inverted to account for that. Yea, shell scripts are kinda messed up.)

Then we need to define a function that'll exit if the mouse is near the corner. We'll call that function check unless you have a better idea for a name. That function exits the program if mouse_near_corner (which we just defined) is true.

Now we can define our main method where we do the GUI automation with xdotool (for now, it'll just type "hello" repeatedly). We just have to make sure we call check before calling xdotool inside the main function, so that the program will halt if the mouse is in the corner.

near(){
	threshold=50
	diff=$(expr ${1#-} - ${2#-})
	return $(expr ${diff#-} \> $threshold )
}

mouse_near_corner() {
	display_geometry=($(xdotool getdisplaygeometry))
	mouse_location=($(xdotool getmouselocation|grep -P -o "(?<=[x,y]:)\d+"|tr "\n" " "))
	if near ${mouse_location[0]} ${display_geometry[0]} || near ${mouse_location[0]} 0; then
		if near ${mouse_location[1]} ${display_geometry[1]} || near ${mouse_location[1]} 0; then
			return 0
		fi
	fi
	return 1
}

check(){ mouse_near_corner && exit; }

main(){ check; xdotool type hello; sleep 1; main; }

main

That may be daunting, but that's how I'd do that in Bash.

3