Whatsapp Command line tool – Linux developer version

wa

Whatsapp, a popular cross-platform mobile messaging app can now be used via simple command line tool too. Whatsapp linux chat client, WA, can be coded in a few minutes from scratch if you have adb installed and ready.

Prerequisites:

adb must be installed and set to environment path. To those who arent familiar with adb, It is a command line interface to interact with android phones and is shipped with developer toolkit.
Once downloaded, it can be added to path variable by updating bash_profile file with below line (located at ~/.bash_profile).

export PATH="$PATH:/Users/hitesh/Documents/personal/adt-bundle-mac-x86_64-20140321/sdk/platform-tools"

Command line tool:

Once your system is ready to interact with android device, we can proceed to make whatsapp command line interface. It will be 11 commands tutorial which I will cover step by step

1. To unlock your phone

adb shell input keyevent 82

If your phone is locked, this command will unlock it for you. For those who are using screen-locks, it can also be automated but it is beyond scope of this tutorial.

2. Restart whatsapp

adb shell am force-stop com.whatsapp

This is done just to avoid running into previously opened whatsapp chat client. We will restart this activity in very next step to avoid any issue.

adb shell am start -n com.whatsapp/.Main

3. Ask for name to which you need to send message

echo -n "Enter Name:"
read name

4. Feed the input name to whatsapp

adb shell input text $name

5. Tap to open chat activity*

adb shell input tap 270 350

6. Ask for message which is to be sent

echo -n "Enter Message:"
read message

Feed the message to whatsapp

adb shell input text $message

It is all set now.

7. Send the message by tapping send button*

adb shell input tap 990 1650

and message is sent.

 

This entire experience can be automated by saving below commands in a file

adb shell input keyevent 82
adb shell am force-stop com.whatsapp
adb shell am start -n com.whatsapp/.Main
echo -n "Enter Name:"
read name
adb shell input text $name
adb shell input tap 270 350
echo -n "Enter Message:"
read message
adb shell input text $message

save this file as wa.sh

It can now be triggered via below command

sh wa

to make it more user friendly,

add this path (can be checked via command pwd) to PATH variable as done for adb command earlier

Now your client is ready to send all messages just by typing wa anywhere

 

Bonus:

If you want to lock out your phone as soon as this is done, Use below command

adb shell input keyevent 26

Or you can remove step 1 too to enter full stealth mode.

 

Disclaimer:

1.This post was written for nexus 5 device and was tried via MacBook. You may need to change parameters in step 5 and 7 if your device is not nexus or prerequisites to set environment variable if you are on a different linux version.

  1. Use Pushbullet to receive messages if you can want that too on your mobile.