EasySMS Launcher

The EasySMS project allows persons with a Google Android phone to send SMS via a PC. It is a web-based application, but requires either USB or WiFi to connect to the phone. Web pages are created by the phone, and the user is able to use them to send text messages, etc. The set up is a little tricky, and requires using ADB (Android Debug Bridge) to connect via USB. Wifi requires entering the IP of the phone into the computer.

This bash script allows for a "button press" approach. It's complete enough to have basic checking, but it's not fool proof. But it's good enough for my use, and I assume it may be useful for others too. It has a Zenity interface (for use with Gnome) but also talks nicely to the terminal. It may require some modifications for use with KDE (just find/replace Zenity with KDEDialog - or whatever it is).

You will need to edit the file, as the first few lines set the ADB location, your preferred browser path, and an icon (for prettiness).

= Bash Script : EasySMS.sh = Also available as a

   .style_2 {		color: #d00000; background-color: #ffffff; }	.style_3 {		color: #007f00; background-color: #ffffff; }	.style_4 {		color: #111199; background-color: #ffffff; font-weight: bold; }	.style_5 {		color: #ff901e; background-color: #ffffff; }	.style_7 {		color: #301010; background-color: #ffffff; }	.style_8 {		color: #000000; background-color: #ffffff; }	.style_9 {		color: #105090; background-color: #ffffff; }	.style_11 {		color: #000000; background-color: #d0d0d0; } #!/bin/bash

#

# EasySMS Starter Script for Wifi and USB

# George SMART (M1GEO)

# Friday, 5th November 2010

#

# http://www.george-smart.co.uk/

#

# Absolute path to adb and a nice icon

ADBPATH = "/opt/android-sdk-linux_86/tools/adb"

ICOPATH <span class="style_7">= <span class="style_5">"/opt/android-sdk-linux_86/android.ico" <span class="style_2"># taken from the google website, not necessary, just pretty.

<span class="style_8">BROWSER <span class="style_7">= <span class="style_5">"google-chrome"

<span class="style_8">echo <span class="style_4">-n <span class="style_5">"Starting EasySMS via "

<span class="style_8">zenity <span class="style_7">-- <span class="style_8">question <span class="style_7">-- <span class="style_8">window-icon <span class="style_7">= <span class="style_5">"$ICOPATH" <span class="style_7">-- <span class="style_8">title <span class="style_7">= <span class="style_5">"EasySMS Starter - George Smart" <span class="style_7">-- <span class="style_8">text <span class="style_7">= <span class="style_5">"Would you like to use USB (via ADB) or Wifi?" <span class="style_7">-- <span class="style_8">ok-label <span class="style_7">= <span class="style_5">"USB" <span class="style_7">-- <span class="style_8">cancel-label <span class="style_7">= <span class="style_5">"Wifi"

<span class="style_4">if <span class="style_7">[ <span class="style_9">$? <span class="style_7">- <span class="style_8">eq <span class="style_3">0 <span class="style_7">]; <span class="style_4">then

<span class="style_2"># USB

<span class="style_8">echo <span class="style_5">"USB"

<span class="style_8">echo <span class="style_5">"Killing any existing adb sessions"

<span class="style_8">killall adb

<span class="style_8">killall adb

<span class="style_8">exitstatus <span class="style_7">= <span class="style_3">1 <span class="style_7">;

<span class="style_8">count <span class="style_7">= <span class="style_3">1

<span class="style_4">if <span class="style_7">[ <span class="style_5">"x$exitstatus" <span class="style_7">!= <span class="style_5">"x0" <span class="style_7">]; <span class="style_4">then

<span class="style_8">zenity <span class="style_7">-- <span class="style_8">info <span class="style_7">-- <span class="style_8">window-icon <span class="style_7">= <span class="style_5">"$ICOPATH" <span class="style_7">-- <span class="style_8">title <span class="style_7">= <span class="style_5">"EasySMS Starter - George Smart" <span class="style_7">-- <span class="style_8">text <span class="style_7">= <span class="style_5">"Starting ADB. Please wait." <span class="style_7">&amp;

<span class="style_8">startbox <span class="style_7">= <span class="style_9">$!

<span class="style_4">while <span class="style_7">[ <span class="style_9">$exitstatus <span class="style_7">- <span class="style_8">ne <span class="style_3">0 <span class="style_7">]; <span class="style_4">do

<span class="style_9">$ADBPATH <span class="style_8">forward tcp <span class="style_7">: <span class="style_3">2511 <span class="style_8">tcp <span class="style_7">: <span class="style_3">2511

<span class="style_8">exitstatus <span class="style_7">= <span class="style_9">$?

<span class="style_8">echo <span class="style_5">"System call exited with $exitstatus on attempt $count"

<span class="style_8">count <span class="style_7">=$(( <span class="style_9">$count <span class="style_7">+ <span class="style_3">1 <span class="style_7">))

<span class="style_2"># after 10 goes, if we cant get adb running nicely, give up.

<span class="style_4">if <span class="style_7">[ <span class="style_9">$count <span class="style_7">- <span class="style_8">eq <span class="style_3">10 <span class="style_7">]; <span class="style_4">then

<span class="style_8">kill <span class="style_9">$startbox <span class="style_2"># remove old zenity message

<span class="style_8">echo <span class="style_5">"There seems to be a problem: ADB won't start nicely!"

<span class="style_8">zenity <span class="style_7">-- <span class="style_8">info <span class="style_7">-- <span class="style_8">window-icon <span class="style_7">= <span class="style_5">"$ICOPATH" <span class="style_7">-- <span class="style_8">title <span class="style_7">= <span class="style_5">"EasySMS Starter - George Smart" <span class="style_7">-- <span class="style_8">text <span class="style_7">= <span class="style_5">"ADB could not be started. Script exiting."

<span class="style_8">sleep <span class="style_3">1

<span class="style_4">exit <span class="style_3">1

<span class="style_4">fi

<span class="style_4">if <span class="style_7">[ <span class="style_9">$exitstatus <span class="style_7">- <span class="style_8">ne <span class="style_3">0 <span class="style_7">]; <span class="style_4">then

<span class="style_8">sleep <span class="style_3">1

<span class="style_4">fi

<span class="style_4">done

<span class="style_4">fi

<span class="style_8">existingpid <span class="style_7">= <span class="style_11">`pgrep adb`

<span class="style_8">msg <span class="style_7">= <span class="style_5">"ADB is now running at PID:$existingpid."

<span class="style_8">phoneip <span class="style_7">= <span class="style_5">"localhost:2511"

<span class="style_4">else

<span class="style_2"># WIFI

<span class="style_8">echo <span class="style_4">-n <span class="style_5">"Wifi to "

<span class="style_8">phoneip <span class="style_7">= <span class="style_11">`zenity --entry --window-icon="$ICOPATH" --title="EasySMS Starter - George Smart" --text="Please enter the IP address of the phone. Note, it must be on a local network."`

<span class="style_8">phoneip <span class="style_7">= <span class="style_5">"$phoneip:2511"

<span class="style_4">if <span class="style_7">[ <span class="style_9">$? <span class="style_7">- <span class="style_8">eq <span class="style_3">0 <span class="style_7">]; <span class="style_4">then

<span class="style_8">echo <span class="style_5">"$phoneip"

<span class="style_4">else

<span class="style_8">echo <span class="style_5">"NaN"

<span class="style_8">zenity <span class="style_7">-- <span class="style_8">info <span class="style_7">-- <span class="style_8">window-icon <span class="style_7">= <span class="style_5">"$ICOPATH" <span class="style_7">-- <span class="style_8">title <span class="style_7">= <span class="style_5">"EasySMS Starter - George Smart" <span class="style_7">-- <span class="style_8">text <span class="style_7">= <span class="style_5">"Cancelled."

<span class="style_8">echo <span class="style_5">"User Cancelled at IP entry."

<span class="style_4">exit <span class="style_7">- <span class="style_3">1

<span class="style_4">fi

<span class="style_8">msg <span class="style_7">= <span class="style_5">"Connect to EasySMS via wifi at $phoneip."

<span class="style_4">fi

<span class="style_8">echo <span class="style_4">-n <span class="style_5">"$msg Launch browswer? (Y/N):"

<span class="style_8">zenity <span class="style_7">-- <span class="style_8">question <span class="style_7">-- <span class="style_8">window-icon <span class="style_7">= <span class="style_5">"$ICOPATH" <span class="style_7">-- <span class="style_8">title <span class="style_7">= <span class="style_5">"EasySMS Starter - George Smart" <span class="style_7">-- <span class="style_8">text <span class="style_7">= <span class="style_5">"$msg\nWould you like this launched in your web browser?" <span class="style_7">-- <span class="style_8">ok-label <span class="style_7">= <span class="style_5">"Yes, Please" <span class="style_7">-- <span class="style_8">cancel-label <span class="style_7">= <span class="style_5">"No, Thanks"

<span class="style_4">if <span class="style_7">[ <span class="style_9">$? <span class="style_7">- <span class="style_8">eq <span class="style_3">0 <span class="style_7">]; <span class="style_4">then

<span class="style_2"># Yes

<span class="style_8">echo <span class="style_5">"Yes"

<span class="style_8">echo <span class="style_5">"Launching: $BROWSER http://$phoneip/index.html"

<span class="style_8">nohup <span class="style_9">$BROWSER <span class="style_5">"http://$phoneip/index.html" <span class="style_7">&amp;

<span class="style_4">else

<span class="style_2"># NO

<span class="style_8">echo <span class="style_5">"No"

<span class="style_8">echo <span class="style_5">"Visit: http://$phoneip/index.html"

<span class="style_8">zenity <span class="style_7">-- <span class="style_8">info <span class="style_7">-- <span class="style_8">window-icon <span class="style_7">= <span class="style_5">"$ICOPATH" <span class="style_7">-- <span class="style_8">title <span class="style_7">= <span class="style_5">"EasySMS Starter - George Smart" <span class="style_7">-- <span class="style_8">text <span class="style_7">= <span class="style_5">"Visit http://$phoneip/index.html with a web browser."

<span class="style_4">fi