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.
Android and Linux
Wednesday, August 25, 2010
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.
First:
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 weather.gov, 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 "www.somesite.com/weather/radar/current.jpg" as the address to the file we want to display. Select the "HTTP Get" and type "www.somesite.com" 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.
First:
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 weather.gov, 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 "www.somesite.com/weather/radar/current.jpg" as the address to the file we want to display. Select the "HTTP Get" and type "www.somesite.com" 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
Tasker
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:
HomeIP:
xx.xxx.xxx.xx
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:
FRM: me@gmail.com
MSG: HomeIP
xx.xxx.xxx.xx
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.
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:
HomeIP:
xx.xxx.xxx.xx
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:
FRM: me@gmail.com
MSG: HomeIP
xx.xxx.xxx.xx
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
Weather
I've always found it simpler and faster to pull weather information from weather.gov 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 http://mobile.weather.gov, 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.
wx-forecast:

wx-current:

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.
To use them, first go to http://mobile.weather.gov, 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.
wx-forecast:
wget -q "LINK" -O - | sed -e 's/<br><br>/\n\n/g' -e 's#<[^>]*>##gCopy "wx-forecast" to your clipboard with this QR code, and don't forget to edit the LINK for your location:

wx-current:
wget -q "LINK" -O - | tr -d '\n' | sed -e 's/<br>/\n/g' -e 's/°//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
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/shCopy "syncpics" to your clipboard with this QR code, but don't forget to edit it to fill out your login information.
rsync -rltDv -e "ssh -l USER -i /PATH/TO/SSHKEY" /sdcard/DCIM/Camera USER@IP:/DIR/TO/SYNC/TO
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:
If my home IP is 123.45.43.21 and that is contained in the .hip file, then "ssh user@123.45.43.21" 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.
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"
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:
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.
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/shAny 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.
cat /sdcard/.hip
If my home IP is 123.45.43.21 and that is contained in the .hip file, then "ssh user@123.45.43.21" 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/shIt 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.
ip=$(lynx -dump http://whatismyipaddress.com | grep "IP Information" | awk '{ print $3 }')
if
grep -q $ip .ip
then echo "IP matched, not sending mail"
else
echo "Sending IP change notification"
echo $ip > .ip
nail 1234567890@txt.att.net < .ip
fi
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/shton1r - recursively transfer a directory. To use, type "ton1r /home/me/somedirectory"
scp -i /PATH/TO/KEY USER@$(hip):"$1" /sdcard
#! /system/bin/shtohome - Sends a file to my computer. To use, type "tohome /sdcard/somedirectory/file.txt"
scp -i /PATH/TO/KEY -r USER@$(hip):"$1" /sdcard
#! /system/bin/shtohomer - Sends a directory to my computer. To use, type "tohomer /sdcard/somedirectory"
scp -i /PATH/TO/KEY "$1" USER@$(hip):/PATH/TO/DIRECTORY
#! /system/bin/shWith my copy/paste trick for the terminal, I use these scripts:
scp -i /PATH/TO/KEY -r "$1" USER@$(hip):/PATH/TO/DIRECTORY
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/shAnd 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.
export DISPLAY=:0.0 && xsel -p && unset DISPLAY
#! /system/bin/shThis one, named "tohomeclip" will take the contents of the phone's clipboard and copy it to the computer.
ssh USER@$(hip) -i /PATH/TO/SSH/KEY 'paste2n1'
#! /system/bin/shI also have these commands set up in GScript, which allows you to run commands or scripts from a home screen shortcut.
clip | ssh USER@$(hip) -i /PATH/TO/SSH/KEY 'export DISPLAY=:0.0 && xclip && unset DISPLAY' && echo "copied to PC:
$(clip)"
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 locate.sh 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!
Here is an example using my locate.sh 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!
Subscribe to:
Comments (Atom)