Skip to content

Instantly share code, notes, and snippets.

@mogenson
Created June 14, 2024 00:51
Show Gist options
  • Save mogenson/808e496dfa2d0320e64538951ea169ec to your computer and use it in GitHub Desktop.
Save mogenson/808e496dfa2d0320e64538951ea169ec to your computer and use it in GitHub Desktop.
Caffeinate for Termux
#!/data/data/com.termux/files/usr/bin/bash -eux
# This script sets the screen timeout to 1 hour to keep the phone awake
# First enable wireless debugging and pkg install android-tools and nmap
# Do adb pair localhost:<port number> and enter code from Settings app
PORT=$(nmap -sT localhost -p30000-49999 | awk -F/ '/tcp open/{print $1}')
echo "Connecting to localhost:$PORT"
adb connect localhost:$PORT || exit 1
cleanup() {
echo "Restoring display timeout to 1 minute"
adb shell settings put system screen_off_timeout 60000
adb disconnect
exit 0
}
trap cleanup SIGTERM SIGINT
echo "Setting display timeout to 1 hour"
adb shell settings put system screen_off_timeout 3600000
sleep 3600 # sleep for one hour
cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment