Skip to content

Instantly share code, notes, and snippets.

@Isanderthul
Forked from TotemaT/sms.sh
Last active January 22, 2018 15:04
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 Isanderthul/e6a1958f060ac86045cc03396fec9326 to your computer and use it in GitHub Desktop.
Save Isanderthul/e6a1958f060ac86045cc03396fec9326 to your computer and use it in GitHub Desktop.
Send an sms from a computer through an Android device using ADB
#!/bin/zsh
# Send text through adb by Madura A.
# https://market.android.com/details?id=org.jraf.android.nolock
# Please use the above app(or similar) to keep it from locking while
# using this script
# If screen is off, turn it on and unlock it (Only works with slide to unlock)
if adb shell dumpsys input_method | grep -q mScreenOn=false; then
$ADB shell input keyevent 26
$ADB shell input swipe 250 650 1000 650
sleep 1
fi
# Check if sms app is already running and close it if it is
test=$($ADB shell ps | grep com.android.mms | awk '{print $9}');
if [ ! -z $test ]; then
$ADB shell am force-stop com.android.mms
fi
# Launch an intent to send an sms with the number and text passed in parameters
adb shell am start -a android.intent.action.SENDTO -d sms:$1 --es sms_body "$2" --ez exit_on_sent true
sleep 1
# Press send button
adb shell input keyevent 22
sleep 1
adb shell input keyevent 66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment