Skip to content

Instantly share code, notes, and snippets.

@PatTheSilent
Created September 24, 2021 07:59
Show Gist options
  • Save PatTheSilent/1eccdc109bbd616658a595809c377d59 to your computer and use it in GitHub Desktop.
Save PatTheSilent/1eccdc109bbd616658a595809c377d59 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# This is a simple yet smart Minecraft autoclicker compatible with X Window Server
# (xdotool does not support Wayland at the time of writing this script)
# To use this autoclicker copy it to your workstation, make it executable and run it.
# Make sure to install https://github.com/jordansissel/xdotool#installation before using this script.
# Minecraft cannot be in fullscreen mode.
# You can put food in your off-hand, the script will hold right click for 4 seconds (enough to eat) every 15 minutes.
# Get all process IDs that match the window class of "Minecraft"
pids=$(xdotool search --class "Minecraft")
# Loop them to find the valid window
for pid in $pids; do
name=$(xdotool getwindowname $pid)
if [[ $name == *"Minecraft"* ]]; then
# Convert decimal PID to hexadecimal
window_id=$(printf 0x"%x\n" $pid)
echo "Start clicking!"
while :; do
echo "Smack em!"
xdotool click --repeat 900 --delay 1000 --window "$window_id" 1
echo "Eating!"
xdotool mousedown --window "$window_id" 3
sleep 4;
xdotool mouseup --window "$window_id" 3
done
# Stop looping
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment