View Single Post
Old 12-11-2012, 12:00 PM   #19
silver18
THE NOOB
silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.
 
silver18's Avatar
 
Posts: 696
Karma: 1545625
Join Date: Jan 2012
Location: Italy
Device: Kindle Touch 5.3.2
How to run custom script from inside a WAF

This work is based on eventHandler by dos1.

The starting point is:
- we need to send an input from inside the WAF
- this input needs to be catched by something ouside the WAF

As regards the first point, we could use the sendEvent property by com.lab126.system.
We used something similar some times ago to take a screenshot from inside a WAF.
So, this time, it's quite the same.

Let's place this in the config.xml file:
Code:
<kindle:messaging>
       	<kindle:app name="com.lab126.system" value="yes"/>
</kindle:messaging>
Now let's send the message (event) using:
Code:
kindle.messaging.sendMessage('com.lab126.system', 'sendEvent', 'YOUR_EVENT_NAME');
You can bind this action to a button or anything else.

If you use
Code:
showlog -f
you can now see the event in your log!!


Now it's time to catch the event.

I altered dos1's script a bit and I called this eventlauncher.sh
Code:
lipc-wait-event -m com.lab126.system YOUR_EVENTS_NAME | while read event; do
	if [[ "$event" == "YOUR_EVENTS_NAME" ]]; then
		PATH_TO_YOUR_SCRIPT &
	fi
done;
You can run a script or a command this way!

Last thing is make eventlauncher.sh running every time you run your WAF.

Create a new upstart script like this:
Code:
# start script for upstart

start on started lab126
stop on stopping lab126

export LANG LC_ALL

respawn

exec PATH_TO_YOUR_EVENTLAUNCHER_SCRIPT/eventlauncher.sh
and place it in /etc/upstart. Restart your kindle.
This way the eventlauncher.sh script is automatically executed at startup and stays active to catch your events.
Please note that playing around in upstart folder is potentially dangerous!

Last edited by silver18; 12-14-2012 at 11:09 AM.
silver18 is offline   Reply With Quote