Android and Linux

Tuesday, December 28, 2010

X10 coolness

I've been slowly getting into X10 home automation lately. It works like this, you get an X10 control module that plugs into the wall near the computer and a cable comes from it and plugs into your computer. Then you get software to control the control module. The control module controls whatever other modules you want to use throughout the house.

The most basic module is the lamp module, which is a small box that plugs into a wall outlet, then your lamp plugs into the module. From the computer, you tell that module to turn on or off.

What happens is that the control module sends a special signal through the wires in your house. The signal is picked up by all the X10 modules you have. The modules themselves have dials where you can select identification letters and numbers on them. You take a module and select, let's say, B4, so that module is now identified as B4. When you send the signal "B4 on," it turns itself on, which turns the lamp on.

There are numerous different modules to do different things. There are wall switches, modules for plug-in electronics like the lamp module and a similar appliance module, security modules, camera modules, dimmers, timers, weather sensors. Anything you can think of, the possibilities are endless.

You can also use them with remote controls and there are a few apps in the Android Market to run them from your phone, but I like setting them up to control from my phone over ssh. There is a Linux program called Heyu for use with the CM11A control module. Heyu can perform nearly two hundred different commands and uses simple command line syntax like heyu on B4. This makes it extremely simple to script, which in turn makes it extremely simple to control through the phone using the basic ssh command I've posted many times:

ssh USER@IP -i /PATH/TO/SSH/KEY 'heyu on B4'

This can be set up as a script to be ran from a terminal, through a GScript shortcut, or with Tasker. Of course, Tasker and X10 make an extremely useful pair.

I really haven't set much up yet except to manually turn a couple of lights on. I plan on getting a module to control the garage door next. This is done by using a "universal module" that acts like a single state button instead of an on/off switch. When the module is activated, it just does it's thing once and there is no way to reverse it. Every time it is activated, it is the same as pushing the garage door opening button so there is no way to know if it is up or down.

I plan to set it up with Tasker to activate it when I am close to home so the door will be open by the time I pull into the driveway. I'm not sure how reliable that will be, so I'll probably add a statusbar reminder that the door is open in case it is activated accidentally.

I've also considered getting a camera for the front door and a doorbell sensor. When someone rings the doorbell, the computer could tell the camera to take a photo then send it to me via MMS. If it looks like someone trying to sell something, I can ignore them. If it's a family member with a birthday present and I'm at work, I can open the garage door so they can come in.

I have no plans to do this, but this would be a cool setup...

Send a notification to the phone when the door is open

Have Tasker silence/ignore the notification if I'm at home and end the task.

If I'm not at home have Tasker say "Sir, I've detected that your garage door is open but you don't appear to be near your house. Would you like me to close it?"

Pop up the voice command window.

Using yes/no, open/closed, up/down as the keyword, I could answer in a natural voice and say "yes please close it for me" or "sure, close that sucker, I must have forgotten" or "nah, leave it up" or "it's ok, I want it open"

It could then say "Ok, closing it now," run the command to close the door and once the sensor detects that the door is closed say "It's closed, sir"

Like I said, I'm not going to do that, but it illustrates how well Tasker and X10 gear could work together to both perform really cool actions like opening doors for you and also make your phone behave somewhat like an intelligent assistant.

Wednesday, December 22, 2010

Happy Holidays!

I haven't been around much lately but I wanted to drop in and wish everyone Happy Holidays. I also wanted to let everyone know that the current economic climate has not affected my Christmas budget and all of the readers of this little blog can expect to receive the same thing I got you last year!

Sunday, November 7, 2010

ssh error and fix

I've helped several people with this so I might as well post it here for others to stumble across. ssh can sometimes give this error:

stderr: ssh: Warning: failed creating //.ssh:
Read-only file system
stderr: Host '[my PC's ip address]' is not in the trusted hosts file

For some reason, ssh is trying to create it's hosts file in /.ssh, which is read-only, giving the error. For me, it happened when trying to use it in a script executed through GScript, but I believe it happens in other circumstances as well.

The solution that has worked for me and a few others is to replace the stock ssh binary in /system/xbin with a link to the ssh binary from Better Terminal Emulator Pro. Unfortunately, BTEP costs money but if you're using ssh or anything else from a terminal, I highly recommend buying it.

After you install Better Terminal Emulator Pro, back up the stock binary by typing this in a terminal:

mv /system/xbin/ssh /system/xbin/ssh.bak

Then put a link in /system/xbin to the BTEP ssh binary:

ln -s /data/data/com.magicandroidapps.bettertermpro/bin/ssh /system/xbin

This has been necessary every time I install an update because they always contain the stock ssh binary. Luckily, this fix has worked every time.

Thursday, November 4, 2010

Finally, a use for twitter

I've never had much use for Twitter but I've recently found myself using my phone to log into my computer to check various things throughout the day. While I have those things set up with GScript shortcuts for quick checking, there's no reason I need to manually be logging in to check them.

You used to be able to post to twitter with curl, but not since they switched to OAuth. Now the simplest way is with TTYtter, the command line Perl Twitter posting script.

Once you run TTYtter and set up your login info, you can post to Twitter using ttytter -status="blah blah blah", but I usually like setting up things to use either pipes or argument type input, plus I'll never remember the name ttytter, so I use this little script named "twit"
#! /bin/sh
if test -z "$1"

in=$(cat /dev/stdin)
ttytter -status="$in"

ttytter -status="$@"

which can be used in two ways:

command | twit


twit blah blah blah

I set up a private twitter account and use TTYter to push various information to it. Some information comes from and hourly cron and for others that run at unexpected times, I just added "| twit" to them.

I use LauncherPro on the phone and it comes with a twitter widget. Set to update every 30 minutes, I just look at the widget to get an update on pretty much anything I may be interested in.

Monday, November 1, 2010

Simple "to do list" voice script for Tasker/voice

I had to do something at work today which required me to examine several things to see if they needed done, do something to them, and mark them off my mental list of things that needed done.

This is something that nearly everyone does on a daily basis but there were just too many items on my todo list to remember them all so I took 10 minutes and whipped up this little script which I named "list".

#! /system/bin/sh
grep -E -i -q "add|delete" /sdcard/.voice || exec echo sorry
grep -E -i -q "^add|^delete" /sdcard/.voice && sed -i 's/^/list /' /sdcard/.voice

COMMAND=$(awk '{ print $2}' /sdcard/.voice)
ARG=$(cut -f3- -d ' ' < /sdcard/.voice)

if [ $COMMAND == "add" ]; then
echo $ARG >> /sdcard/list
echo "Added: $ARG"

elif [ $COMMAND == "delete" ]; then
sed -i "/$ARG/d" /sdcard/list
echo "Deleted: $ARG"

This simply adds or deletes things from a list based on whether it finds "add blah blah blah" or "delete blah blah blah" in the file at /sdcard/.voice.

I created a new task in Tasker with the following actions:

1- Variable set %LIST to EOF
2- Locale Execute Plugin: @ list
3- Wait 500ms
4- Read Paragraph /sdcard/list to var %LIST
5- Flash %LIST

I set this to trigger on the keyword "list**" with the Tasker voice command I've been talking about in the last few posts. The end result is this:

I say "list add go to work"

It flashes:
go to work

I say "list add pay bills"

It flashes:
go to work
pay bills

I say "list delete work"

It flashes:
pay bills

I say "list add go on vacation"
It flashes:
pay bills
go on vacation

I say "list delete bills"
It flashes:
go on vacation

I say "list add sleep late"
It flashes:
go on vacation
sleep late

I added a line in the script to make this loopable. The line I added will add "list" to the beginning if it's not there already and execute normally. If called by the normal voice task, you still have to say "list add/delete blah blah blah" because "list" is the trigger word, but when called in a loop, you can just say "add/delete blah blah blah" and the script will recognize it. This makes it possible to keep using the list while performing your duties.

Saturday, October 30, 2010

Speech recognition on Linux, through cheating

Speech recognition on Linux is hard to come by. I've been looking for a long time and never found anything that is very useful.

Most of the solutions available are nothing more than libraries for developing speech recognition programs which require you to build your own language models. They're mostly meant to be used in other software. Many of them look like they're very well done but I'm not a credit card company looking to set up a call canter so incorporating them are well above my ability. After playing around with a few of these, I decided they were a no-go.

I was hoping there would be a solution in the cloud, like an API to Google's online voice recognition engine, but Google doesn't have one and there don't appear to be any others available either.

So I decided to cheat. All I really need is to be able to say a few simple words and have it translated to a text file. I have voice recognition on my phone that does that, so why not use it?

To avoid repeating myself, this, like everything else on my blog lately, uses ssh with keys, Tasker with the Locale Execute Plugin, the Google voice recognition API called with Python that appear in my last few posts and a short script on the phone.

The short script we need is this, which I will call "vhome" for my examples:
#! /system/bin/sh
cat /sdcard/.voice | ssh USER@IP -i /PATH/TO/SSH/KEY 'cat > /PATH/TO/A/FILE && /PC/COMMAND/SCRIPT'
All this script does is place the text from the /sdcard/.voice file into a file on your computer. From my previous posts, it should be clear how Tasker/Python/Google all work together to get your words into a file on your phone and this simply gets that file to your computer.

The "&& ..." is optional and used for executing a script on the computer which will do something with the text. This example assumes you do want to use that because I didn't pre-filter it on the phone so the file on the computer will literally contain "computer [commands to be carried out]".

The script on the computer would get rid of the first word and parse the rest for keywords linked to commands to execute. It could be as simple as one if/elif loop to look for matches and run commands. This can then be easily added to for new commands by inserting a new elif/then line for the keywords to match and commands to run.

Now it's as simple as setting up the Tasker task to trigger the script on a keyword, like "computer" for example and say "computer [commands to be carried out]".

An example of using this would be saying "computer search more common hades." The script on the computer would get rid of "computer" and using an if/then loop would recognize "search" as a keyword, read the rest of the text into a variable and run this command:
firefox "$VAR"
The biggest downside is speed. It takes about 8-9 seconds from start of the voice API to command execution on the computer. One way to make this useful may be to set up a task in Tasker that keeps looping until you say a keyword to stop it. A quick example would be:

1- Write File .voice (this is used to zero out the file)
2- Run Script
3- Read Paragraph file: .voice to %VOICE
4- Goto Action 3 if %VOICE matches EOF
5- Stop If %VOICE matches halt
6- Locale Execute Plugin execute vhome If %VOICE matches computer
7 Goto 1

This task would show the voice recognition prompt. When you say "computer [commands to carry out]", it will execute vhome then show the voice recognition prompt again, unless you said "halt", in which case it dumps out of the loop and exits. Using this, you can place the phone on your desk and have voice commands at the ready.

So, that's about all. You now have speech recognition on Linux, thanks to cheating.

If you're also interested in speech synthesis on Linux, I suggest grabbing a good TTS engine like Festival and replacing the default diphone voice with a better one. Some of the most popular are the ARCTIC voices from Carnegie Mellon's Language Technologies Institute or the HTS version of those voices from the HTS working group at Nagoya Institute of Technology. The voice I use is "cmu_us_slt_arctic_hts". I haven't tried many TTS engines because Festival seems to do everything I want, especially taking text piped to it from a shell. This makes it pretty easy to set up a script that can be called to make the computer talk on certain events. You can add it to the examples above so your computer says "Yes sir, I'm opening the search results for More Common Hades."

Monday, October 25, 2010

Voice command/Tasker errata

More natural commands

Having played around with voice commands a little after my last post, I decided my speech wasn't natural enough. Wait, what? With voice commands and speech synthesis, isn't it usually the computer that doesn't sound natural? Well in this case, it certainly doesn't feel natural to look at my phone and say "Forecast. Tuesday."

Based on the commands and tasks in my last post, I would say "forecast tuesday" and the word "forecast" would trigger the forecast task and the second word would be used to prepare the forecast for the correct day.

I've gravitated toward this solution for filtering my voice commands, when they need filtering.
awk '{print $NF}' /sdcard/.voice > /sdcard/.voicetmp
then changing the task from this:

5- Perform Action WXDAY if %VOICE matches forecast**

to this:

5- Perform Action WXDAY if %VOICE matches **forecast**

No big difference, but where it did depend on the first and second word before, now the first word can be anywhere in the sentence and the second word only needs to be at the end. Now "What's the forecast for friday?" or "Boy, I sure do wish my phone could tell me what the forecast is supposed to be for the day of the 29th, which just happens to be a friday" will both work and sound a lot better than "Forecast. Friday."

I'm only using the weather task as an example since it's been posted here. This can be used with any command which needs to extract a trigger and a variable from your speech.

I haven't had the need to input multiple variables yet, but I did whip up a couple scripts to give that flexibility:
#! /system/bin/sh
if test -z "$1"
tr ' ' '\n' < /sdcard/.voice | tail -n1 > /sdcard/.voicetmp
tr ' ' '\n' < /sdcard/.voice | tail -n${1} > /sdcard/.voicetmp
You can execute this script followed by the number of items you want to extract, or followed by nothing for extracting one item. For example, if you want to extract three items and the script is named "vfilter," you'd put "vfilter 3" in the Locale Execute Plugin then set up your task accordingly.

I'm not sure what use this is, but I hate being constrained to only being able to use a single word so I hammered this out and put it on my sdcard in case I need it.

Another approach, if you need more flexibility, would be to say the number, and execute either of these commands:
#! /system/bin/sh
awk '{ for(i=$NF;(NF-i)<NF;i--) { printf "%s%s",$(NF-i),FS } printf RS }' /sdcard/.voice > /sdcard/.voicetmp
awk '{ for(i=$NF;(NF-i)<NF;i--) { printf "%s%s",$(NF-i),FS } printf RS }'  /sdcard/.voice | tr ' ' '\n' > /sdcard/.voicetmp
The only difference is that the first one will output everything on one line and the second will output each word on it's own line.

Using this, you can say "Please google more common hades three" and using google as a keyword to open a search URL, it will input the last three words "more common hades."

Of course, this is more easily accomplished by using "google" as a variable split point and using VAR2 as the search term, but, who knows, it might come in handy for a flexible task where you need to input a different number of items on the fly without changing a handful of actions in the task.

Temp files

You may have noticed I used .voice and .voicetmp as temp files. You can bypass temp files by putting the words directly into the system clipboard by editing the Python script to this:
import android
droid = android.Android()
Speech = droid.recognizeSpeech()[1]
I toyed around with this and decided it was simpler to use files. Other tasks may set or use the clipboard and there may be something important in the clipboard that I don't want to erase by an unrelated task, and it's easier to set up tasks without worrying about backing up the clipboard every time.

Now that the human side sounds better...

Oh yeah, I haven't really mentioned speech synthesis here. The only thing worth mentioning is that the best voices I've heard are made by Svox and are available in the Market. They have many voices and a free app that gives a sample of them all. I personally like the British female voice. When using Tasker, I set the tone to 6 and speed to 10 and o-la-la does she sound good.

Do I have any cool voice tasks?

Probably not. I actually have 15 tasks that are controlled by voice, but some are for controlling my home computer over ssh and are probably only interesting to me. Here are a few that may be useful. I won't post the whole task, just the idea. The rest should be easy to figure out.

Saying "pic" takes a photo.

Saying "text" runs the voice script twice more, once to get the SMS recipient, again to get the SMS body, then opens the SMS app and fills out the text.

Saying "map [address]" opens the map to the address I specify.

Saying "search [phrase]" opens google search of the phrase.

I'm trying to buy a house so saying "mls search [number]" opens the browser to[number] to look up homes by their MLS listing.

I have all those in a separate task which the voice task executes. After that, it executes another task which is just for loading apps. I have a dozen set up to open on command, like saying "terminal" opens the terminal, saying "mail" opens gmail, etc. I haven't really used them, but it's another example of using voice control. Other voice apps can open apps by name, but how can they possibly interpret names like "BTEP" or "QuickSSHD?" Using your own voice control, you can open them by nicknames, which is much more powerful.

Monday, October 18, 2010

Speech recognition with Tasker

The Android Scripting Environment, now called SL4A, is now working with Tasker and on the Tasker Google group, a user named baudi posted an example of using a Python script for calling the Google voice search API.

His example uses the camera button to execute the script. Since the Nexus One doesn't have a camera button, I just set up the task and used it with a widget instead and combined both tasks into one. I left the Python alone (probably a good idea since I don't know Python) except to rename it as and rename the output file to /sdcard/.voice because I hate typing long filenames.

Here's a rundown of my Task:

1- Write File .voice (this is used to zero out the file)
2- Run Script
3- Read Paragraph file: .voice to %VOICE
4- Goto Action 3 if %VOICE matches EOF
5 ... whatever you want

When you run this, it executes the python script which pops up the Google voice search API which translates your speech to text then puts that text in a file which Tasker reads into a variable.

Ho hum, what good is this?

Well for starters, you can carry out tasks if that text matches a predefined string. For example, using my last two posts about sharing the clipboard contents between a Linux computer and the phone, I can speak the words "copy" and "paste." Once Tasker recognizes them, it carries out the tasks to copy the clipboard from the computer to the phone, or send the phone's clipboard to the computer's. This can be done simply by adding this as step 5, where XXX is the task to send or pull the clipboard contents and YYY is the word to trigger it:

5- Perform Action XXX if %VOICE matches YYY

Another example, I took this simple script and changed it quite a bit to get the weather current conditions and forecast and use Tasker to download it every hour and put it in a text file called "/sdcard/.metar" (the actual script also grabs METAR weather data from another site). The forecast looks like this:

Saturday...Partly sunny. Highs in the lower 70s.

Saturday Night...Mostly cloudy. Lows in the upper 40s.

Sunday...Partly sunny. Highs in the mid 70s.

Sunday Night...Mostly cloudy. Lows in the lower 50s.


Now, make this script called "wxday"
#! /system/bin/sh
grep -i $(awkc '{print $2}' /sdcard/.voice) /sdcard/.metar > /sdcard/.wxday
In the voice task above, step 5 can be:
5- Perform Action WXDAY if %VOICE matches forecast**

Here is the WXDAY task:

1- Locale Execute Plugin: execute @! wxday
2- Read Paragraph file: .wxday to var %WXDAY
3- Goto 2 if %WXDAY matches EOF
4- Say %WXDAY

Now, I can tap the voice widget, say "forecast Thrusday," it will see that I said "forecast" and call the WXDAY action. That action extracts Thursday from my weather file and speaks the forecast for Thursday.

Is Android/Tasker cool or what?

Sunday, October 3, 2010

Android to Linux clipboard, again

(Note: I did a more complete write-up on the XDA forum which may be easier to follow than this.)

Using Tasker, my previous method can be improved and, unlike pasting from the PC to phone, this one works perfectly because it's not limited by Tasker's inability to read an entire file.

Using the link above, get the computer ready with the "n1_to_comp" script, then make a little script on the phone:
#! /system/bin/sh
cat /sdcard/tohomeclip | ssh USER@IP -i /PATH/TO/SSHKEY 'n1_to_comp'
In this example, I'll name that script "2homeclip."

Here is the Task to set up with Tasker:

1- Write File > tohomeclip > text %CLIP
2- using the Locale Execute Plugin execute @! 2homeclip

That's it!

How are this post and the last one an improvement? If it's not clear, it's my fault for having a messy blog, but if you click the link above then click the link at the top of that post, you'll see that copying and pasting in the terminal previously needed an intermediary app that could save the clipboard in a plain text file. And doing it in a terminal wasn't my goal. I wanted to share clipboards system-wide. Since Tasker can interact with the clipboard and run scripts, we can do away with that other app.

But isn't it still using an extra app? Yes and no. Tasker is required, but it can do everything I wanted. Where it previously required running the script and opening the other app to interact with the clipboard (or vice-versa) by setting up these two copy/paste tasks as two widgets (or one widget which pops up both and allows you to pick), copying and pasting between the computer and phone only requires a single click.

Wednesday, September 29, 2010

Linux clipboard to Android, again

(Note: I did a more complete write-up on the XDA forum which may be easier to follow than this.)

Tasker offers an improvement to my previous method of sharing clipboard contents between the phone and linux PC. It's not perfect yet, because there is no reliable way to read a whole file, but Pent said on the Tasker discussion group he'd put that on his todo list.

As of now, this will copy one line perfectly, giving it the same functionality as "Chrome to Phone" to send links to your browser. With a little customization, you could probably get it to imitate the rest of Chrome to Phone's functionality, and this would work on non-Froyo phones too, although it requires ssh with keys, at least rudimentary command line knowledge and only works on Linux and with Tasker, and only on weekdays when the sun it out and your car is full of gas.

Ok, some of that is not required.

Using my previous example in the link above, set up the paste2n1 script on your computer to export the display and grab the clipboard contents from the command line using xsel or xclip.

Once that is done, set up a script on your phone to ssh to the PC and run that script then redirect the output to a file on the sdcard. I'll use /sdacrd/homeclipboard in this example, so your phone script should look something like: ssh USER@IP -i KEYFILE 'paste2n1' > /sdcard/homeclipboard

Now here are the actions to use with Tasker:

1- using the Locale Execute Plugin, execute the script you just wrote for the phone.
2- Variable clear > %LINE
3- Variable set > %ONE to 1
4- Read line > file: homeclipboard, Line: %ONE, To Var: %LINE
5- Set Clipboard %LINE
6- Flash > %LINE
7- Browse URL > URL: %LINE if %LINE matches http*

The last three steps are optional and depend on what you want to do with this task. Step 5 copies it to your phone's clipboard, step 6 pops up a toast notification showing you what was copied and step 7 opens that line in the browser if it is a http link, imitating Chrome To Phone.

If you followed this far, it shouldn't be too hard to figure out how to send a link to the computer. In fact, you should be able to send anything in the clipboard to the computer, as the limiting factor for going the other direction is Tasker's inability to read a whole file and keep the newlines and blank lines intact. The computer doesn't have that problem, so all you'd have to do is use Tasker to write %CLIP to a file then use the Locale Execute Plugin to run a srcipt which transfers it to the computer's clipboard.

After attempting to use this over the cell network today, I realized the rest of the task runs while the first step is still executing, thus copying "old" text to the phone's clipboard. An easy fix is to add Delete File> homeclipboard as the first step, then after the "Read line" action, add a "Go To [the "Read Line"] > if %LINE matches EOF." %LINE will always be EOF until the script execution completes and the homeclipboard file is created.

This could create an infinite loop in Tasker if the connection to the computer is down, as the file would never be created. Another simple way to avoid that would be to add a conditional to the script such as ssh USER@IP -i KEYFILE 'paste2n1' > /sdcard/homeclipboard || echo "failed" > /sdcard/homeclipboard. If it successfully connects, you get the clipboard text. If it fails, you get a failure notice copied to the phone's clipboard, or you could add a step to Tasker to pop up a warning if %LINE matches "Failed" and then stop the Task. There's a lot of simple ways to go about it but, personally, my connection never fails so I'm just winging it.

Friday, September 10, 2010

Tasker car profile

At the risk of turning this into a Tasker blog, I thought I would share my new use. Now that I have a sweet car dock, I needed to set up Tasker to do a few things when I docked and undocked the phone.

When I enter the Jeep, I wanted the screen to go to full brightness, GPS to turn on and WIFI to turn off. When I exit, I want to mark my location with GPS, dim the screen to normal, turn GPS off, turn wifi back to the state it was in when I entered, and play a sound to remind me to grab the phone. I also don't want this to always happen when I plug the phone in, so I needed an option to turn it off easily.

I didn't read any other car dock profiles online and did this on my own, so I probably did it entirely the wrong way, but here goes. I did it all in several separate steps.

The first is a Task called "JeepOn" with the following steps.

1 Variable Clear %WIFISTATE
2 Variable Clear %GPSSTATE
3 Variable Set %WIFISTATE to 1 if %WIFI matches "on"
4 Variable Set %GPSSTATE to 1 if %GPS matches "on"
5 Display Brightness 255
6 Wifi Off
7 GPS On
8 Flash "Jeep Mode"

That's pretty simple. It records whether the GPS and WIFI are on, turns GPS on, WIFI off, and brightens the screen.

The second is called "JeepOff"
1 Variable Set %BEACON to %LOC
2 GPS off
3 WIFI On if %WIFISTATE equals 1
4 Flash "Jeep Mode Off.
Wifi: %WIFI
Beacon set with %LOA m accuracy."
5 Notify Sound. [pick a sound file] Title "Jeep Mode Off"
6 Wait 5 seconds
7 Notify Cancel
8 Display Brightness 40

Here's an explanation of what this does.
1- This records my GPS position into a variable called %BEACON. I have a widget set up that simply opens Maps and take me back to that spot. This is done by selecting "Navigate To" mode "and putting %BEACON in the lat/long field.
2- Turns off GPS
3- Sets WIFI to the state it was in before. I'm not sure how useful this will be, but I have wifi set to turn on and off at certain times of the day so this should help it stick to that schedule.
4- Tells me the WIFI/GPS state and how accurate the beacon was set
5-7 - Plays a sound to remind me not to forget the phone. Since the only way to play a sound is by using a statusbar notification, which I don't really want, the next two steps are for clearing the notification without having to open the notification bar.
8 - dims the screen to the level I usually keep it on.

I'm not sure if my car charger shows up as AC or USB, but I use both at home and don't want all this to happen every time I plug the phone in, so I wanted to be able to disable Jeep Mode. I did this in two steps. The first is a new profile for "Power - source - any" called "JeepMode" with the action "Perform Task - JeepOn" and the exit action "Perform Task - JeepOff". Then I added a new Tasker widget to the homescreen and added the action Profile Status - JeepMode - Toggle. Tapping the widget turns it on if it was off, and vice versa.

So, if I'm sitting around the house I can leave JeepMode turned off and plug in the phone at will. If I'm going to drive to work and don't need JeepMode, I can plug in without it, but if I'm doing a lot of driving and getting in and out of the vehicle and think I'll need it all day long, I tap the toggle and it stays on until I tap it again.

Thursday, September 9, 2010

$8 car dock

Car docks from HTC are $60, but I just got all the parts to make my own, thanks to this great idea. The parts plus shipping cost $8.

I would post a photo, but I've torn the house apart and can't find my roll of double-sided tape anywhere, so the parts are just staring at me, wishing they could be assembled into something useful.

Wednesday, August 25, 2010

Yet more Tasker

Gosh, I still haven't had time to devle deeply into it, but this app can apparently do anything.

Using this guide, I set up Tasker to locate my phone. When it gets an SMS with a certain codeword, it turns on GPS, waits for a good fix, then sends a reply with the coordinates and a link to a google map. This is good for traveling, in case you lose your phone, or for people to locate you in an emergency.

With this guide, I set up two widgets for marking a point and locating it. It creats two icons, the first marks your location and stores it in a variable and the second maps that variable. It's great for temporarily marking a spot and finding your way back to it.

I'm also using it to sync the photos from my phone to my computer when the phone connects to my home wifi using my earlier rsync command. This is easily set up in Tasker by selecting New > State > Wifi Connected and typing in my wifi SSID, then using the Locale Execute plugin to run the script.

That's all for now, but I'm sure I'll find a lot more uses for this app.

Monday, August 16, 2010

A couple more Tasker uses

I haven't had much time to play with Tasker and only skimmed the documentation and what I read seemed hard to understand. Well, maybe "hard to skim" is a better description. Anyway, I thought it may be useful to someone to post a couple more examples I've found useful.


Like most people, I leave GPS off unless I need it for a certain app. I usually forget to turn it on until after opening the app, then have to exit, turn it on and re-open the app, but now I have Tasker set to automatically turn on GPS when certain apps are opened. For this example, I will use the Maps app and here's how it's done.

Open Tasker and click "New" then "Application" and select "Maps" (or whichever app you want to use). On the next screen, click "+", "Misc", "GPS" select "On" and click "Done".

If you want it to pop up a message telling you GPS has been turned on, click "+", "Alert", "Popup" (or Notify if you prefer it in the notification bar), enter your text, e.g. "GPS Turned On" and "Done." You can also select how long to display the notification. The default is 5 seconds but I found 1 second to be better.

Now it will turn on GPS when the app is opened, but we also want to turn it off when it closes, so click Done again and get back to the main screen. Now click on the "GPS On" box and click "Add Exit Task". Click "+", "Misc", "GPS" select "Off" and click "Done". Again, if you want it to display a message when GPS is turned off, follow the same steps from above.

Now it will turn GPS on when you open the app and turn it off when the app closes. Pretty simple.

There is another way to set up this GPS On/Off task for easy repetition for multiple apps. From the main screen, click "Tasks", "New", enter "GPS On" or "GPS Off" then follow the On/Off setup above. Now it will be recorded as a task and if you want to use the same setup for another app, click "New", "Application", "+", "Tasker", "Perform Task" then select your task from the list.

Second Tasker use:

I have a short script here which employs an idea by Nathan Harrington from IBM. His perl script can be used to download a weather radar map from, draw a custom-sized square around your location and check for precipitation inside that square.

Mine is what you might call a notification wrapper to his perl script and the end result is that it checks every 15 minutes and, if there is any rain within a 20 mile square centered around my house, it sends me an SMS saying "Local precipitaion detected." This has been extremely reliable for me and I usually get an alert 10-15 minutes before the first drop starts falling.

Whenever I get that message, I usually open WeatherBug and check the radar, so I set Tasker to open it for me. This is easily set up by opening Tasker, selecting "New", "Event", "Phone", "Received SMS" and entering "*Local precipitaion detected*" in the Message field. Once that is done, click the "+" on the next screen, select "App" then "WeatherBug."

I've also found a similar use. I went to two local news station websites and found good static weather radar images, copied the links and use the "http poster" locale plugin to download both images and the "Popup Image" Tasker option to display them when I get that SMS. These are quicker than loading the maps in WeatherBug and can quickly show if there is only one small spot of rain on the way or a big storm.

I'll leave most of this setup as an exercise to the reader, but I'll give these tips for using the HTTP plugin. Let's use "" as the address to the file we want to display. Select the "HTTP Get" and type "" in the "Server:Port" box. Under "Path", put "weather/radar/current.jpg". I'm not sure it's necessary, but under "MIME Tpye", I selected "image/*". Now put an output file and use that file name when you set up the next task, which will be "+", "Alert" and "Popup Image."

I'm not sure which of these I will use, but I've been having fun thinking of ways to use Tasker and simple tasks like these are pretty easy to figure out once you start playing with it.

Wednesday, August 11, 2010


I've seen the app called Locale in the Market for a while and it seemed interesting. It allows you to do a lot of things automatically with the phone under certain conditions such as turning wifi on when you get home or putting your phone on silent at certain times. It looked nice but I didn't think I had much use for it until I noticed a Locale plugin called "Locale Execute" which allows you to execute scripts under whatever conditions you set. My first thought was "Cron!"

I started to download Locale but a lot of comments said it wasn't as good as Tasker. Since Locale is $10 and has no trial version, I installed the trial from the Tasker site. I played around with it for a day and decided to buy the full version.

Tasker looks pretty powerful. It can perform 160 built-in actions on virtually any conditions. Some of the conditions include time, location, day, application, various phone states (battery levels, plugging in headphones or USB, network connections, orientation, etc), various events (file opened or modified, display on or off, boot, shutdown, sdcard (un)mounted/removed, phone calls and SMS, gestures etc).

Talk about an app to show off to iPhone users.

So far, I've added a profile from their wiki which pops up a menu of shortcuts to all my audio apps whenever I plug in my headphones. I can then select which media app I want to use, Youtube, BeyondPod, Music, RockPlayer, etc.

Then I set up a location profile to turn on wifi when I'm within 200 meters of my house. This uses the cell tower for a location fix so GPS is not needed. I was previously using Timeriffic to turn it on at times which I'm normally home, but now it does it when I'm actually there.

Then I found a cooler use. You may remember my ip checking script that runs from cron on my home PC. It checks every 15 minutes and sends me a text message if the home IP address changes. I then copy the IP and put it in /sdcard/.hip to call from any scripts that connect to my PC. The command that calls it is a script named "hip", which stands for "Home IP" and simply does "cat /sdcard/.hip".

I've been using the same trick for well over a year and a half, since I had the iPhone, and always wanted a way to automatically put the IP in the /sdcard/.hip file. Such a simple task, but there's really no way to get the text from the SMS into a script, but it's quite simple with Tasker.

All I had to do was set it up to take action when a new SMS was received, which can be done according to the sender or the body of the SMS. The action I told it to take was to write to the file /sdcard/.hip.

One problem was that I send the SMS from sendmail using my Gmail address and I use a similar SMS trick for three different purposes, so I couldn't use the sender and had to use the body. I didn't see a way to have it look for an IP address, so I put a string in the SMS and had it look for that. I had to figure out how to do a wildcard, as that isn't documented on the Tasker site, but my script at home now sends this:


I set tasker to look for "*HomeIP*". Apparently both asterisks are required for a wildcard as it didn't work with only one. Tasker writes the entire SMS to the file, including the sender, so /sdcard/.hip ends up looking like this:


I simply changed my "hip" script to: "tail -n1 /sdcard/.hip"

That's a pretty simple setup to solve a simple problem, but being able to automatically write files, or do any of the other things Tasker is capable of, on virtually any conditions, looks to be quite promising and powerful.

Monday, August 2, 2010


I've always found it simpler and faster to pull weather information from than to use a weather program. I normally use lynx to dump the page on a computer, but it's not available for Android, so I made these using wget. These small scripts can get weather information in about half a second, which is faster than opening a weather app and navigating to the information you want.

To use them, first go to, type in your zip code, then it will take you to a page with the following links:

Detailed 7-day Forecast
Your Local Radar
Current Conditions
Satellite Image
Hazardous Weather
Area Forecast Discussion

Copy the links for "Detailed 7-day Forecast" and "Current Conditions" to use in these commands.

wget -q "LINK" -O - | sed -e 's/<br><br>/\n\n/g' -e 's#<[^>]*>##g
Copy "wx-forecast" to your clipboard with this QR code, and don't forget to edit the LINK for your location:

wget -q "LINK" -O - | tr -d '\n' | sed -e 's/<br>/\n/g' -e 's/&deg;//g' -e 's#<[^>]*>##g' | grep -v -E '(Current|Service|Lat:)'
Copy "wx-current" to your clipboard with this QR code, and don't forget to edit the LINK for your location:

If you want to run these from GScript shortcuts, GScript has a bug that makes text unscrollable over a certain number of lines and the forecast puts out too much information, so you only see the last few lines which are the last few days of the 7-day forecast. I found that running wx-forecast | grep -A 9 "Last Update" should gives you 4 lines of forecast info. Since days are split up between day and night, this will give you the forecast for approximately the next 36 hours, which is pretty much as far out as a forecast is reliable anyway.

Wednesday, July 21, 2010

Backup photos with rsync

I've never used rsync much but have always wanted to try it more. Maybe it was my inexperience or maybe it's the non-standard Android version, but it turned out to be a pain!

I started with a generic rsync command and customized it, but every step failed and I had to find the answer why. Then, after a successful connection and transfer, it threw errors on every file, which I found was due to a bug in some versions of rsync, so I had to find a workaround to that.

At any rate, here is a basic, working rsync command for transferring photos from the phone to a computer.

It can be used to back up any directory by changing "/sdcard/DCIM/Camera" to the directory you want to backup. It can also transfer files from the computer to the phone by changing the order of the two paths from /sdcard/DCIM/Camera COMPUSER@IP:/PATH/TO/SYNC/TO to COMPUSER@IP:/PATH/ON/COMP /PATH/ON/PHONE
#! /system/bin/sh
rsync -rltDv -e "ssh -l USER -i /PATH/TO/SSHKEY" /sdcard/DCIM/Camera USER@IP:/DIR/TO/SYNC/TO
Copy "syncpics" to your clipboard with this QR code, but don't forget to edit it to fill out your login information.

Monday, July 19, 2010

Various Linux/phone ssh transfer commands

ssh is wonderful for computer to computer communication and here are a few scripts which I use for PC <-> phone communication:

First, most of these use ssh and to log in without a password, they use ssh keys. There are numerous tutorials for setting up ssh keys, but I always point people to this site because it's a relatively clear explanation. Since this is an Android related blog, the Cyanogen wiki article on using Dropbear for ssh is more geared to our phones.

Once ssh keys are set up, one problem that may be encountered is your home IP address. You don't want to hard code it into a bunch of scripts in case it were to change, plus you may not be able to log in if it changes unless the computer notifies you in some way.

My solution is to store my home IP address in a hidden file on my sdcard named ".hip", which stands for "Home IP." Then I have a simple script named "hip" to display the contents of that file:
#! /system/bin/sh
cat /sdcard/.hip
Any time I write a script or command to connect to my computer, I put the "hip" command in a subshell so that it executes and places my IP address wherever it belongs in the script.

If my home IP is and that is contained in the .hip file, then "ssh user@" is the same thing as "ssh user@$(hip)"

I have a cable connection and my IP changes any time the cable goes out, which is once every couple of months. I have this script running on a cron job at home every hour to check for an IP change.
#! /bin/sh
ip=$(lynx -dump | grep "IP Information" | awk '{ print $3 }')
grep -q $ip .ip
then echo "IP matched, not sending mail"
echo "Sending IP change notification"
echo $ip > .ip
nail < .ip
It records the address in a file, checks the current IP and compares the two. It then sends a text message to my phone if they change. I can then put the new address in my .hip file and all my scripts work again.

Now, on to the fun stuff. Here are a few for transferring files:

ton1 - used to grab a file from my computer to the phone. To use, type "ton1 /home/me/somedirectory/file.txt"
#! /system/bin/sh
scp -i /PATH/TO/KEY USER@$(hip):"$1" /sdcard
ton1r - recursively transfer a directory. To use, type "ton1r /home/me/somedirectory"
#! /system/bin/sh
scp -i /PATH/TO/KEY -r USER@$(hip):"$1" /sdcard
tohome - Sends a file to my computer. To use, type "tohome /sdcard/somedirectory/file.txt"
#! /system/bin/sh
tohomer - Sends a directory to my computer. To use, type "tohomer /sdcard/somedirectory"
#! /system/bin/sh
scp -i /PATH/TO/KEY -r "$1" USER@$(hip):/PATH/TO/DIRECTORY
With my copy/paste trick for the terminal, I use these scripts:

First, I have this script named "paste2n1" on my home computer so I can log in at any time and get the clipboard contents without having to export the display:
#! /bin/sh
export DISPLAY=:0.0 && xsel -p && unset DISPLAY
And on the phone, this one is named "homeclip" and it logs in and runs the paste2n1 script, displaying the PC clipboard in the phone's terminal.
#! /system/bin/sh
ssh USER@$(hip) -i /PATH/TO/SSH/KEY 'paste2n1'
This one, named "tohomeclip" will take the contents of the phone's clipboard and copy it to the computer.
#! /system/bin/sh
clip | ssh USER@$(hip) -i /PATH/TO/SSH/KEY 'export DISPLAY=:0.0 && xclip && unset DISPLAY' && echo "copied to PC:
I also have these commands set up in GScript, which allows you to run commands or scripts from a home screen shortcut.
homeclip | copy
- transfers PC's clipboard contents to the phone's clipboard
ton1 $(homeclip)
- Allows me to copy a file name on the PC and transfer it to the phone.
ton1r $(homeclip)
- Same thing, except it works with a directory.

Once you can access your computer with your phone from anywhere in the world, and do it with very simple scripts, your mind tends to think of ways to use it, and these are just some examples of simple fun you can have with ssh.

Wednesday, June 30, 2010

QR Codes

I'm going to start adding QR codes to scripts I post here. QR codes are neat, but I've never found much use for them until I realized Barcode Scanner has an option to copy text from QR codes to the clipboard. Cool.

Here is an example using my script, and the preview from Barcode Scanner.

Note, there is no button in Barcode Scanner to save as a file, but if you hit the menu, there is an option to automatically save text to the clipboard. If that's turned on, you just scan the code then open a text editor and paste.

I'm not sure anyone will find any use for the codes, but getting the script to the phone is the number one problem users have with my iphone language deletion script. I get 100 hits a day to that page and it seems like 50% have trouble getting it on the phone. Too bad QR codes can only handle 4000 characters and that puppy is over 9700.

None of the online qr code generators work very well. I couldn't find any that encoded newlines so the whole script would end up being copied on one line. I finally decided to see what was available for Linux and ran across the qrencode command line utility which seems to work perfectly.

I'll be going back and adding them soon. EDIT: Done!

Saturday, June 26, 2010

Another unix tool (poorly) imitated

Android doesn't have a whois command, so I hammered one out the best I could. Unfortunately, it looks up the info from the website, which could potentially change and render this useless, and it currently only works with IP addresses. It's not perfect, but it's the only whois for Android I know of.

It can be done with domain names, but the output is different depending on the server the whois site gets the info from, and that makes it impossible to predict which lines to extract. I did put in a -p "please" option to semi-work with domain names. It will look up the IP address for the domain, then do a whois on the IP. It fails sometimes, which is why I used it as an option.

This will also be uploaded to the script section of the L.E.S. Linux Android app, which just had an update and is working with Froyo now.

#! /system/bin/sh
if test -z "$1"; then exec echo "USAGE: ip_address, -p for please, --help for more info"; fi
case "$1" in

echo ' by fubaya (
Another cheap imitation of a missing unix tool. This simply displays the output of a search on the website.
It currently only works with IP addresses, however with the -p (please) option,
it can use the ping command to get the IP address then look up the whois information for that IP.'

if echo $2 | grep -q [a-z]
ip=$(ping -c 1 ${2} | grep PING | awk '{ print $3 }' | tr -d "()")
if test -z $ip; then exec echo "Sorry, something went wrong with the ping lookup for this domain.
Try getting rid of the 'http://'"; fi
wget -q -O -${ip}/ | sed -e 's/&nbsp;/ /g' -e 's#<[^>]*>##g' | awk 'BEGIN{ RS="Extended Info"}{gsub(/.*Domain Search/,"");print;exit}' | sed "/^$/{N
else exec echo "I was looking for an alphabetic domain name but didn't see one and got confused. Exiting."

if echo $1 | grep -q [a-z]
then exec echo "Sorry, this only works with IP addresses unless you specify the -p option. Please see --help first."; fi
wget -q -O -${1}/ | sed -e 's/&nbsp;/ /g' -e 's#<[^>]*>##g' | awk 'BEGIN{ RS="Extended Info"}{gsub(/.*Domain Search/,"");print;exit}' | sed "/^$/{

Copy to your clipboard with this QR code:

Thursday, May 27, 2010

Copy/paste between Linux and N1

Using my post about copy/paste in the Android terminal, it becomes easy to share clipboard contents between your phone and Linux.

First, you need a way to access the Linux clipboard from a terminal. I use either xclip or xsel. Both are old programs which always seem to work differently for each application, so this example uses both.

You need to set up ssh keys to login to your home computer from the phone. The general layout for using keys in a script is something like: ssh USER@IP -i KEYFILE. You can also briefly login to a computer and run a command over ssh by using: ssh USER@IP -i KEYFILE 'command' and that's what we'll be doing.

In order to get the computers clipboard contents, we'll use the command "xsel -p." Since xclip and xsel are utilities meant to interact with the X display, you may also need to export the display then unset the display in order to get a clean logout with ssh. For simplicity, I made a script called paste2n1 which can be ran with the ssh command.

#! /bin/sh
export DISPLAY=:0.0
xsel -p

Now I can run this command to display the computer's clipboard on my phone:
ssh USER@IP -i KEYFILE 'paste2n1'

By piping it to the copy script I posted previously and running this command from gscript, I can copy the computer's clipboard contents to the phone with one tap of an icon on the phone.

ssh USER@IP -i KEYFILE 'paste2n1' | copy

To paste the phone's clipboard contents to the computer, I'll use xclip with this script named n1_to_comp on the computer:
#! /bin/sh
in=$(cat /dev/stdin) # or "in=$(cat -)"
export DISPLAY=:0.0
echo "$in" | xclip

ssh supports most commands through pipes so you can send any text to the computer with the command: ssh USER@IP -i KEYFILE 'n1_to_comp'

You could use that as a flexible all-around paste command/script to paste any output to the comptuer such as: cat textfile | ssh USER@IP -i KEYFILE 'n1_to_comp'

Or use my previous command I called "clip" for pasting the phone's clipboard in the terminal for a one touch clipboard-to-clipboard transfer using gscript: clip | ssh USER@IP -i KEYFILE 'n1_to_comp'

These are just examples and instead of piping to different scripts, you could write a simple one-liner for each operation. I may write a single script with options to handle both operations if I get bored.

Sunday, May 23, 2010

I polished and uploaded my locate script to L.E.S. Linux. It can be found in L.E.S. under the name "" or here:
#! /system/bin/sh

if test -z "$1"; then exec echo "USAGE: [filename|-u|--help]"; fi

case "$1" in
echo ' by fubaya (
This is a cheap imitation of the UNIX locate command. It stores
a list of all the files on your system to /sdcard/.locatedb (about 2MB)
then greps that file to find whatever you are looking for.

USAGE: [filename|-u|--help]

[filename] case insensitive search for any file of any type.

-u update the "database." This must be ran periodically if you want to
find new files. I have it set to run at boot on phone.

--help display this help message

EXAMPLE: $ cd /; touch /data/testfile
$ testfile
$ -u
database updated
$ testfile
find / -print > /sdcard/.locatedb && echo "database updated"
grep -i "$1" /sdcard/.locatedb

Copy to your clipboard with this QR code:

Thursday, May 20, 2010

Whereis redux

I made my little whereis script a little better and uploaded it to the Android app L.E.S. Linux.

L.E.S. Linux is a cool little app which allows you to download Linux executables, scripts and libraries which have been compiled or made for Android. I will probably put any scripts which I think may be useful on L.E.S. The only other one I have in mind so far is the little "locate" script which I'll upload after I make it a little more presentable.

Here is the whereis script I uploaded. I named it to avoid confusion with the real (but missing on Android) whereis executable but, oops, I accidentally called it "whereis" instead of "" in the actual script. Oh well.

#! /system/bin/sh

if test -z "$1"
echo " by fubaya (
This is a cheap imitation of the UNIX whereis command.
It doesn't imitate all the whereis functions, it only looks in your
path for the binary (or other file) which you specify as an argument.

USAGE: whereis [arg]
$ whereis date
echo $PATH | tr ':' '\n' | while read line; do ls "${line}/${1}" 2>/dev/null; done

Copy to your clipboard with this QR code:

Monday, May 3, 2010

Paste in an Android terminal

I've always found it useful to be able to paste the clipboard contents in a terminal. I often find links in the Browser that I want to download with wget, but how to get the link into terminal without having to type it out?

My brief search for how clipboard content is stored yielded no results. It would be nice if it was stored in a file so we could grab the contents, but it's probably held in memory. At any rate, there is a workaround very similar to the workaround I used on the iPhone.

I went looking for some sort of clipboard helper app that does store the clipboard in a text file. The one I settled on is called Clipstore by benishouga and it stores the clipboard contents in a plain text file at /data/data/jp.benishouga.clipstore/files/clip.txt.

It is meant to keep a clipboard history of multiple items and it stores every entry on a single line. It replaces newlines with a "n" tag so even if you have 20 clipboard history items consisting of multiple lines, the most recent item will always be on top and it will all be on a single line. So the paste script can simply be:
#! /system/bin/sh
# Requires the app "Clipstore" by benishouga and app must be opened or allowed to
# run in the background in order to transfer system clipboard to app clipboard
sed 's/<n>/\n/g;q' /data/data/jp.benishouga.clipstore/files/clip.txt
I suggest not naming it "paste" to avoid any conflicts with the unix command of the same name. I named it "clip".

Copy "clip" to your clipboard with this QR code:

I may try to figure out a way to do a copy command soon, but it isn't usually as handy.

Update: Copying text is actually pretty easy using Clipstore. You just have to stick the text in the file at /data/data/jp.benishouga.clipstore/files/clip.txt, but to use it, you have to open Clipstore and select the text. This makes Clipstore put it in the system's clipboard and it can then be pasted in any app. Neither the copy or paste are perfect, but I don't know of a way to access the system clipboard directly. Neither command is needed very often, although they're lifesavers when they are, so having an extra step isn't really a problem.

Here's the copy script:
#! /system/bin/sh
# Requires the app "Clipstore" by benishouga and text must be
# selected in Clipstore to transfer it to the system clipboard
in=$(cat -)
lines=$(echo "$in" | wc -l)
if [ "$lines" = 1 ]
then sed -i "1i\\
$in" /data/data/jp.benishouga.clipstore/files/clip.txt
inn=$(echo "$in" | sed ':a;N;s/\n//g')
sed -i "1i\\
$inn" /data/data/jp.benishouga.clipstore/files/clip.txt

Copy the "copy" script to your clipboard with this QR code:

Wednesday, April 28, 2010

Dump a webpage in terminal

This doesn't work as well an lynx -dump, but is a simple alternative that does work pretty well for some pages. It uses wget to dump the raw html to stdout, then sed to clean out the javascript and html tags. I also have an optional grep tacked on the end to get rid of lines of text from Google Adsense which can add up to quite a bit on pages which use it. That was just something that was present on the pages I tested it with and I figured I might as well leave it.

The first line is a test to check for proper formatting of the link. The wget present on Android phones is a stripped down Busybox version which requires the http before the address and simply won't work for "". The script checks for the http and adds it if it's not present, so if you type "dump", it should still work.

Unfortunately, it doesn't work well at all on pages containing css.

#! /system/bin/sh
echo $1 | grep -q http || pre="http://"
wget -q ${pre}${1} -O - | sed -e '/<script type="text\/javascript"/,/<\/script>/d' -e 's#<[^>]*>##g' | grep -v googleAdd

Copy "dump" to your clipboard with this QR code:

Friday, April 16, 2010

Two more missing Linux commands imitated

The "man" and "whatis" commands are two more useful command line utilities that are missing from Android. Here are two more scripts to imitate their function.

These require a network connection because they download information from For this reason, there is no guarantee the information will be accurate for your system. This information is normally installed when the program is installed, but it's not on Android so the best I can do is grab general information off the web.

Please note, you may already have a man command if you have Busybox installed. My Nexus One with Cyanogenmod has man located at /system/xbin/bb/man but it is just a link to Busybox and it didn't work so I just deleted it.

You can use my previous whereis command to see if you have a man command installed:

# whereis man

Then run "ls -l /system/xbin/bb/man". If it is a link to busybox, the output will contain this: "/system/xbin/bb/man -> /system/xbin/busybox" and you are safe to delete it. To restore it later, just create a link to busybox named "man".

Anyway, here are the scripts:

#! /system/bin/sh
wget -q -O - "${1}" | grep -A 1000 NAME | sed -e 's/<[^>]*>//g' -e 's/^[ \t]*//'

Copy "man" to your clipboard with this QR code:

#! /system/bin/sh
wget -q -O - "${1}" | grep "\- " | head -1 | sed 's/^[ \t]*//'

Copy "whatis" to your clipboard with this QR code:

Saturday, April 10, 2010

Replacing missing utilities

These two scripts were rewritten and improved. Here are the improved versions of whereis and locate.

The Nexus One, and Android in general, is missing a few basic unix utilities, but we can imitate them with short shell scripts.

#! /system/bin/sh
echo $PATH | tr ':' '\n' | while read line; do ls "${line}/${1}" 2>/dev/null; done
The whereis command is used to locate executables. This script will go through every directory in your path and try to list the executable you specify as an argument. If it doesn't find it, the errors go to /dev/null so you only see output if it is found.

# whereis grep
# whereis sh

#! /system/bin/sh
grep -i "$1" /sdcard/stuff/files
The locate command is a bit like the find command, except faster. When it is ran in update mode, it searches through the system and compiles a database of all files, so when asked to locate a certain string, it is able to do so almost instantly by searching it's database. This uses the find command to list all files and put them in my fake locate database at /sdcard/stuff/files, but it could use any file or location you want.

# locate ncurses
# locate livewallpaper

#! /system/bin/sh
find / -print > /sdcard/stuff/files
This updates the locate database. Like the normal locate command, it has to be ran once before the locate script will work or else the database will be empty and it won't locate anything.

Sunday, March 28, 2010


Hi and welcome to the blog. I am JM, a.k.a. Fubaya on many forums. This blog will relate to the Nexus One smartphone and Linux and will probably focus on the BASH shell and small scripts for use on the phone or for communicating between the two, much like my blog relating to the iPhone and Linux.