Skip to content

Instantly share code, notes, and snippets.

@jaredrummler
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredrummler/bd52e2f04b0e461be718 to your computer and use it in GitHub Desktop.
Save jaredrummler/bd52e2f04b0e461be718 to your computer and use it in GitHub Desktop.
Use the terminal to enter text on Android devices.
#!/bin/sh
#############################################
#
# text.sh inputs text on Android devices
# using adb shell.
#
# author: Jared Rummler
# since: Oct 22, 2014
# version: 1.0
#
cat > ./temp.sh << EOF
#!/system/bin/sh
phrase="\$@"
length=\$(echo "\$phrase" | wc -w)
n=0
for i in \$phrase
do
let n++
input text \$i
if [ \$n -lt \$length ]
then
# Add a space between words.
input keyevent 62
fi
done
EOF
adb="adb wait-for-device"
$adb push ./temp.sh /sdcard/temp.sh
$adb shell su -c "cp /sdcard/temp.sh /data/local/temp.sh"
$adb shell sh -c "rm /sdcard/temp.sh"
$adb shell su -c "chmod 0755 /data/local/temp.sh"
$adb shell su -c "sh /data/local/temp.sh $@"
$adb shell su -c "rm /data/local/temp.sh"
rm ./temp.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment