hdweiss edited this page Feb 7, 2012 · 27 revisions

MobileOrg for Android supports some scripting features

** Invoking the capture interface from outside the application**

Start the capture screen by invoking the following action: com.matburt.mobileorg.CAPTURE (or com.matburt.mobileorg.donate.CAPTURE) It also takes a intent extra called 'txtValue' that will pre-populate the Capture interface's text box

Here's an example of a Python ASE/SL4A script that captures a note via the speech system and sends it to the capture interface

  import android
  droid = android.Android()
  message = droid.recognizeSpeech("Capture New Note").result
  a = droid.startActivity("com.matburt.mobileorg.CAPTURE", None, None, {'txtValue':message}, False)

Voice Capturing with Tasker

Instead of SL4A you can also use Tasker. The following recipe is designed to capture new items completely hands-free. I use with when driving my car. I wish this task could also be started by a voice command with vlingo, but I haven't found a way yet. So you still have to press an icon on your home screen to start the task.

This Tasker task will first speak a welcome message, showing the readiness of the phone to listen to you. It will then repeat what Android recognized as your input. You can then decide if the input was understood correctly and proceed (press OK) or, if the recognition failed (what happens quite often), you can cancel and start once again.

Create a new task with Tasker, name it OrgCapture (or whatever).

Assign a series of actions to it:

  • Variable Set, Name: %SAVECLIP To: %CLIP, If %CLIP is set
  • Set Clipboard, Text: ?, Add: not checked
  • Say, Text: Hey Sven. I'm your trusted system. Please feed me with some stuff, Engine:Voice: com.svox.pico.eng-USA, Stream: Media
  • Run Script, (this is a SL4A script, see below), Terminal: unchecked
  • Wait, 110 ms, Until: %CLIP !~ ?
  • Say, Text: You said: %CLIP, engine and stream like above. This repeats what you have said in step d)
  • Set Clipboard, Text: %SAVECLIP, If: %SAVECLIP is set
  • Variable Query, Name: %HIT, Input Type: Numeric/Integer
  • If, %HIT Is set
  • Action Intent, Action: com.matburt.mobileorg.CAPTURE, Cat: None, Extra: txtValue:%CLIP, Target: Activity
  • Variable Clear, Name:%SAVECLIP

Assign an Icon to the task, I use the unicorn of MobileOrg.

Create a shortcut on your homescreen.

The SL4A script which is called in step d) looks like this:

import android
droid = android.Android()

How to remind yourself that you have captured some new items en route?

When back on your Computer at home you might already have forgotten about your newly captured items. If you have already synced, these show up in the file, but contain no TAGs or TODO keywords. Therefore, they probably won't show up in your Agenda Views in Emacs. What I do to remind myself about the new entries that need to be refiled etc., is letting a Cronjob probe if there are some new items in the file and print its content directly onto the desktop with Conky. The following will not work with Windows, I don't know about Mac. Anyway, you have to install Conky.

First you need a script that regularly executes org-mobile-pull (on that occasion you can also do a fresh push):

   emacs --batch --load ~/.emacs --eval "(org-mobile-pull)" --eval "(org-mobile-push)"

Save the script under ~/bin/org-mobile-sync/ (or whatever).

Second, create a script that checks if has some content and starts Conky to display it:

   ORGFILE="/home/sven/Dropbox/myconf/" # replace that path according to your needs.
   KILLNR="$(ps ax | grep "conky -c .*conkyrc-mobile" | grep -v grep | sed 's/ pts.*//g')"
   NEWTASK="$(cat $ORGFILE | grep -v auto-revert | grep -v ^$ | grep -v 20[0-9][0-9])"

   if [ -n "$NEWTASK" ];
       if [ -n "$KILLNR" ];
           conky -c ~/.conkyrc-mobile &
       if [ -n "$KILLNR" ];
           kill $KILLNR

Save this one under ~/bin/org-mobile-sync/ (or whatever). Note that my contains the first line -- mode: auto-revert; mode: org; -- If you don't use auto-revert you can delete the respective pipe in the definition of NEWTASK.

Third, you need a special config-file for Conky with the name given in the above script (~/.conkyrc-mobile):

own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
use_spacer right
use_xft yes
xftfont DejaVu Sans:size=18
xftalpha 0.8
text_buffer_size 2048
update_interval 3.0
draw_shades no
draw_outline no # amplifies text if yes
draw_borders no
uppercase no
border_margin 9
border_width 10
default_color grey
own_window_colour brown
own_window_transparent yes
alignment top_right
gap_x 10
gap_y 10
${Color green}NEW TASKS
${execi 10 cat /home/sven/Dropbox/myconf/ | grep -v auto-revert \
| grep -v ^$ | grep -v 20[0-9][0-9]}$color

Fourth, set up the cronjobs, here is how my crontab looks like:

  */30 * * *	* sh /home/sven/bin/org-mobile-sync/ >/dev/null 2>&1
  */35 * * * * DISPLAY=:0.0 /home/sven/bin/org-mobile-sync/ >/dev/null 2>&1