Skip to content

Instantly share code, notes, and snippets.

@tremby
Created January 6, 2012 18:08
Show Gist options
  • Save tremby/1571701 to your computer and use it in GitHub Desktop.
Save tremby/1571701 to your computer and use it in GitHub Desktop.
topleft -- move mouse pointer to top left of current screen
#!/bin/bash
# check for binaries
type -P xmousepos &>/dev/null || {
echo "can't find xmousepos -- install xautomation" >&2
exit 1
}
type -P xte &>/dev/null || {
echo "can't find xte -- install xautomation" >&2
exit 1
}
# get current horizontal mouse position
mousex=$(xmousepos | awk '{print $1}')
# walk through widths of screens (assuming they're in order left to right) until
# the mouse is on the current screen, building offset from left
offset=0
for width in $(xrandr | grep '*' | awk '{print $1}' | sed -r 's/x.*//'); do
[ $mousex -lt $(expr $offset + $width) ] && break
offset=$(expr $offset + $width)
done
# move the pointer to the top left of the screen
xte "mousemove $offset 0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment