[General Questions and Answers] angusc:
Hi,

I want to learn some of the commands for use in SManager (Script Manager) for ANDROID.

https://sites.google.com/site/devwom/script-manager

Does anyone know a suitable thread with guide or commands for SManager? I tried searching the web and XDA but did not find anything myself.

Specifically I want to know the cmd line to start an app.

EDIT 1:

Spent a good few hours trying to google a solution but drawn a blank.......Maybe Shell Scripts for Linux are not same as for Android...?

I would like to be able to run a script that does the following:

Checks if a directory exists on the sdcard

then executes a command (renaming of 2 directories)

then starts a program

EDIT 2:

well a few emails with the author of SManager and I was able to write my first script to check if the app is running and then if not, to rename folders and start the other version of the app. (I have Navigon Europe as well as Navigon Australia and was looking for a solution to allow both to co exist on my One-X at the same time. As both apps share the same directory structure the issue was that starting one version would overwrite the critical files of the other).

Now with my script installed as a widget I can toggle between each version without problem.

Here is some useful information on shell language for others (credits to the author of SManager Devwom):

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Here are some critical bits of info received during my emails with him:

Thanks a lot for your interest in SManager.

The requested commands is a mix between linux commands and android os commands.

To get info about each command you can search in google and select the preferred page.

But the commands available in each Android device depends on running rom.

To get all available commands in your device, simply execute a ls (lower case LS) in system directories, that is:

ls /system/bin

ls /system/sbin

ls /system/xbin

ls /system/usr/bin

ls /system/usr/sbin

ls /system/usr/xbin

These are the most common directories where binaries resides in android devices.

May be you also can have commands at:

ls /bin

ls /sbin

ls /usr/bin

ls /usr/sbin

usually android rooted roms have the well known busybox, to get a list all comands inside it simply execute

busybox

to get all installed packages (and running names) from your device you can execute:

pm list packages

to get info about running process

ps

or

ps aux

or

ps -aux

depending on ps version installed

If conditions are based on test bash command this command is a bit confused, because usually it is named as [, and other times it is built-in inside shell

read "test man page" to get a full list of test command flags.

To check if an app is running:

if [ -n "$(ps|grep os.tools.scriptmanager)" ] ; then

echo SManager is running

fi

To check if app is NOT running:

if [ -z "$(ps|grep os.tools.scriptmanager)" ] ; then

echo SManager is NOT running

fi

To check if a file exist:

if [ -e /sdcard/file ] ; then

echo /sdcard/file exists

fi

To check if a file exist and it is a directory:

if [ -d /sdcard/file ] ; then

echo /sdcard/file exists and is directory

fi

To rename a directory simply use mv command:

I hope you can build your script with this info.

Start app it is very easy but getting correct info to start app is a bit confused.

starting app uses "am command"

To get correct info to start app you should execute:

logcat |grep Starting

in a terminal on device

then go to launcher and launch desired app

then go back to the terminal and you will see a line with info about how to fill am command.

For example if you execute SManager

in

logcat|grep Starting

output you will see

I/ActivityManager(* 275): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=os.tools.scriptmanager/.launcherActivity } from pid 377

so to start scriptmanager you need the following command

am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n os.tools.scriptmanager/.launcherActivity

I do not know how to stop apps from command line, I usually use killall command:

killall os.tools.scriptmanager

if you do not have killall command you can use grep and awk or cut commands

kill "$(ps|grep os.tools.scriptmanager|grep -v grep|awk '{print $2;}')"

or

kill "$(ps|grep os.tools.scriptmanager|grep -v grep|cut -f5 -d" ")"

may you need adjust -f5 flag

To execute script as shortcut install SMWidgets.

Scripts usually ends with last line :), ie, not special action is required, it will exit with the last executed command return code

Also you can add

exit 0

or preferred exit value, but 0 usually means OK

To end script in the middle use

exit value

where value usually it is not 0

Also it is better use mv command instead rename command.

rename command it is not linux standard, but mv command is in all linux shells.

Android shell programing it is not equals to linux shell programming but this was one of my first scripting documents many years ago :) and it can be used as a guide. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Best regards,

Devwom