My favorites | Sign in
Logo
                
Search
for
Updated Sep 29, 2009 by damonkohler
Labels: Featured
UserGuide  
An introduction to ASE.

Having trouble? Got questions? Check the FAQ or try the ASE discussion group.

Introduction

Android Scripting Environment (ASE) provides interactive interpreters, script editing, and script execution for various scripting languages. The easiest way to get started is to look at the example scripts that are installed with ASE. Then, have a look at the Javadoc for the AndroidFacade API and the AndroidProxy API.

Script Manager

After starting ASE, you'll see the script manager. From the script manager you can create new scripts, edit existing ones, launch scripts, launch scripts as services, and create shortcuts on the home screen.

To add a new script, press the menu button and choose "New." To edit an existing script, create a shortcut, or launch it as a service, long click on the script name.

Script Editor

When creating a new script, or editing an existing one, the script editor will be displayed. The top text box is the filename of the script. The lower text box is the script content.

In order for ASE to know what interpreter to launch your script with, it will look at the file extension. Use .lua and .bsh for Lua and BeanShell respectively.

Interactive Terminals

Scripting languages that support interactive terminals can be launched via the terminal menu in the script manager.

Home Screen

By long clicking on the home screen, you can create a short cut to an existing script.

Locale Plugin

ASE includes a Locale plugin which allows executing scripts via Locales situation engine. For example, you could launch a script when you arrive at work, or at 5PM, or when a particular Wifi network is in range.

Running Scripts Externally

Sometimes it's nice to be able to write scripts on your computer and run them on the phone. This is possible using adb's port forwarding.

First, start an ASE interactive terminal in either Python or Lua. Take note of the AP_PORT variable at the top of the terminal. Next, set up adb port forwarding and set the AP_PORT environment variable locally.

$ adb forward tcp:4321 tcp:<AP_PORT>
$ export AP_PORT=4321

Now you can execute Python or Lua on your PC, import the android package or module for the language, and interact with the AndroidProxy on the phone.

For example, to use your local Python interpreter, make sure you have the ASE android.py module in your Python path (i.e. in site-packages or the current directory).

$ python
Python 2.6
Type "help", "copyright", "credits" or "license" for more information.
>>> import android  # The ASE android.py module should be on your sys.path.
>>> droid = android.Android()
>>> droid.makeToast("Hello from my computer!")

Comment by doug.bromley, Jul 11, 2009

If you get an error stating that no device is found then make sure you've enabled "USB debugging" in Home > Menu > Applications > Development.

Comment by rusty0101, Jul 15, 2009

To use the android.py and adb you will need to install the Android SDK appropriate for your platform. See http://developer.android.com/index.html for further information. It is not included as part of the Android Scripting Engine.

Comment by tawani, Sep 24, 2009

Is it possible to evaluate a javascript string expression from within an android app?

Normally in java, you will do something like this: Java:

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
       
        try {
            String expression = "3+4";
            Object result = engine.eval(expression);
            System.out.println(expression+" = "+result);
        } catch(ScriptException se) {
            se.printStackTrace();
        }

/**
    output: 3+4 = 7.0
**/

Is this possible in android?

Comment by damonkohler, Oct 04, 2009

@tawani I'm not sure, but I'll give that a try when I get around to trying to add JS to ASE.

Comment by neil_m_s...@hotmail.com, Oct 04, 2009

Hello,

I'm new to using ASE, so I apologise if this is a really obvious point, but I just wondered if it was possible to get a little more precise information on how to run scripts externally (as briefly discussed above). Does the phone actually need to be plugged into the PC (via USB) or will this work across a network (ideally I'm hoping to go over wifi on my phone, which has is set up for access to my network, to communicate with my PC)

Many thanks Neil

Comment by damonkohler, Oct 06, 2009

@neil_m_stoker Presently, yes, you'll need to have the phone plugged into USB for the above method to work. I'm planning to make this, easier however (i.e. no need for adb and support connecting via WiFi?).

Comment by fotoflo, Nov 04, 2009

hmm, i wrote a simple script to send text messages from ARGV in perl, but when i try to run it from adb it says "cannot connect to server port 4321 on localhost" -- i did as you instructed: (from dos) "adb forward tcp:4321 tcp:45691" and then "set AP_PORT=4321" but it still doesn't work. Not sure I understand what is happening anyway... Would love an extra line or two of explanation.

Comment by damonkohler, Nov 14, 2009

@fotoflo I'm not familiar with how it works on Windows. But it sounds like you've done the right things. Maybe you have a firewall issue?

Comment by tad.guski, Nov 19 (5 days ago)

I tried to do some simple scripts using for loops and such. Its hard to do anything without access to commands like sed or basename or other basic commands. Everytime I try them, I get Permission Denied. Any ideas?

Comment by aitrus72, Nov 20 (4 days ago)

Seems like the locale plugin would be much more useful if it allowed you to launch a script as a service instead of bringing up the terminal every time the condition is triggered. Am I just missing something?


Sign in to add a comment