[Fire TV General] harlekinwashere:
This is a posting mostly on concepts and what is possible with adb scripting, and a few best practices on how to implement it to be actually usable. :)

So what is this about?

Lets say you'd want to start Pandora on your FireTV and start a specific playlist with just a click or two on your smartphone. Favorite songs, skip tracks, and so on and so forth.

Of course this is only the tip of the iceberg of what is possible. :)

Things you need.

- a (preferably rooted) FireTV or FireTV stick (tested and working on firmware version 5.0.5)

- an android smartphone

- preferably a PC with adb installed to get things going

This is how you do it.

The way automation works is mostly using adb touch events (essentially "click on coordinates x y" on a 1920 1080 screen (for example)), and using adb key events (input keyevent 19 = click "up" once (for example), google android keyevents to get a full list, or read on for a link), separated by specified amounts of sleep [seconds] (for example sleep 10) inputs to give the FireTV enough time to execute the commands.

To repeat -

a touch event looks like this:

input tap 960 978 && sleep 0.8

a key input event look like this:

input keyevent 19 && input keyevent 19 && sleep 0.8

(input "up" twice, then sleep for 0.8 seconds

you can find other keyevent codes here:

http://stackoverflow.com/questions/7789826/adb-shell-input-events)

You use && (a bash scripting "linking" item) to link several commands together. (Essentially - once the previous command is finished, continue to the next, then continue to the next, then continue to the..)

The first usable example you should learn is how to start Kodi using adb scripting:

adb shell monkey -p org.xbmc.kodi 1 && sleep 5 && exit

To find the process name (f.e. org.xbmc.kodi) of a specific app, launch the app, then adb into the fire tv, open a shell (adb shell), then use ps | grep kodi to show all running processes with the word kodi in their process name. Replace kodi to find others. :)

Because much of this process relies on you being able to specify certain x y coordinates to "touch on" via adb scripting - the next command you should learn is to pull a screencapture off your FireTV to your desktop.

This is done via:

adb shell screencap -p /sdcard/screencap.png
adb pull /sdcard/screencap.png ~/Desktop/screencap.png

Notice that ~/Desktop/screencap.png is a filepath on a system running either Linux or MacOS - if you are running adb from a Windows mashine (to set things up, later we move script execution to your Android smartphone - promised.. :) ), you might have to specify a different path. :)

Using those screenshots you can grab x y coordinates quite easily (using an image editing program starting from the top left corner of each image). You use those x y coordinates to set up adb touch events later.

-

Once you have completed a certain script (f.e. start Pandora - navigate to playlists, start a specific playlist) and tested it success fully via the PC (much easer to write them there than on a smartphone.. ;) ) - you can start to move them over to the smartphone side.

Here is how you do that.

Since google has removed adb as an executable binary from Android from Marshmallow forward - you have to use an app to compensate. :)

The app you want to use is "Remote ADB Shell":

http://xdaforums.com/showthread.php?p=68972640

(In that thread you also find two complex examples of FiretTV scripting I use quite frequently - and a write up on how to modify the scripts to work with the app.)

Because "Remote ADB Shell" currently only supports a shell history lookup in case you don't want to write the entire script into the command line each time, there is a final step you should go through to make launching the scripts from your android smartphone more feasible.

Create a folder (preferably in /system) on the Fire TV and move all scripts as individual .sh files into that folder. Name them appropriately (f.e. /system/scripts/pandora_start.sh). Make them executable (chmod 755).

(The fastest way to do both steps on a rooted (necessary to move the .sh scripts to a folder in /system - which also is necessary - because NOTHING on /sdcard/ can be set to be executable (Android security)) Fire TV is to use Total Commander (App is in the Amazon Appstore).)

Then execute the script files (just text files with the actual lines of scripting you did beforehand, and the file extension .sh) from "Remote ADB Shell". (f.e. by typing in /system/scripts/pandora_start.sh && exit )

Notice that when you write the script files (.sh), or execute scripts form "Remote ADB Shell" - you have to leave out the "adb shell" part at the start of every command. As "Remote ADB Shell" will start you in the adb shell per default, so you don't have to address it, the app does that for you.

If you need a little more assistance on the last part (how to get this working on an Android Smartphone), read my two postings in http://xdaforums.com/showthread.php?p=68972640 - it should make things a little easier to grasp. (You can find specific examples and a screenshot of how it looks in the end there.):)

Also - don't forget to always exit cleanly out of the shell and adb, because the Fire TV only allows one adb connection at a time. In "Remote ADB Shell" it is enough to type in exit into the shell (add && exit to every command you execute there), if you connect from a PC - you might have to exit adb using adb disconnect, to establish another adb connection.

Also - don't forget, that you can restart the adb server on the Fire TV via the settings toggle (adb off then back on), if you cant establish a connection.

If you don't know what this is about, or how to use adb (adb connect IP .... I wont explain this in detail here...), too bad. ;)

It's an actually easy and worthwhile way to get to know what is possible via adb and command line scripting on the Fire TV.

If you are stuck, I'm happy to assist - so ask questions if you have to. But don't ask for step by steps.

Start with thinking, contemplating and trial and error first.

When you create the folder and/or move files to said folder in /system - make sure you don't delete any other directories and or files there "by accident". Behave responsibly. ;)

so long

h.