Forged together with one chain

In this paper, as I am an active enthusiast of Joao Dias, a Portuguese application developer, and his motto: “Automate your life,” I will show how you can make your life much simpler, automate the problems requiring communication between your smartphone and a computer, another smartphone or a tablet PC.

In particular, we will consider such problems as sending a text from a tablet PC to computer and vice versa, sensing files to a phone/tablet PC from the context menu of standard Windows explorer. We will know how to receive notices about events occurring on computer at your smartphone, how to synchronize file from a certain folder on computer with the device and vice versa virtually instantly (excluding the time on file upload), how to tune voice control by means of smartphone, etc.

The main program that will perform our actions on the device is Tasker. The responsibility for communication will be borne by the AutoRemote plug-in, for voice transmission of commands — by AutoVoice and for operations with personal computer — by a program for Windows EventGhost. Certain actions will require the availability of root, Android Version 4.2 and higher and the BusyBox program installed.

I’d like to make a reservation straight away that the paper is presumed on those who are already familiar with Tasker. Well, if you hear about it for the first time — please visit the magazine’s archive.

Tasker

First of all, install Tasker. We will use it as an event handler at the device. I recommend to use the English localization in the program and disable the beginner mode for manipulations with profiles. Designations taken herein: “profile” determines the conditions for operation of an event or a state in response to which the task will be performed, which consists of one or more actions.

We will also need a plug-in for Tasker named AutoRemote. It will catch Tasker events and in reply send data to other devices or to computer or, vice versa, receive data and run a certain Tasker profile.

After the first run the AutoRemote plug-in will generate two important parameters which will be necessary for subsequent actions. They are Personal URL in the form of goo.gl/XxXx and Personal key, which can be found by going according to Personal URL link. A record of the following form will be displayed in the browser’s address line: http://autoremotejoaomgcd.appspot.com/?key=YyYyY, where symbols after = denote the Personal Key. It must be remembered or copied in the notepad.

Tasker and AutoRemote should be installed on all devices which will take part in communication. Then at every device we are to run AutoRemote, transfer to the Registered Devices tab (phone symbol) and enter it into the Personal URL field of another device. In addition, it is possible to scan the QR-code of the device, which is shown on the main screen of the application.

Example: transfer of the copied text to another device

I will give a simple example of the profile in order to demonstrate the principle of operation of the Tasker + AutoRemote connective. Create a task on device 1 with the action of Plugin -> AutoRemote Message. Select device 2 in the Device field, enter copy=:=%CLIP in the Message field. This action will send the command copy=:= with the text from the buffer of the telephone/tablet PC exchange to device 2. For more usability, create a Tasker widget on the desktop and select the task created in its settings having preliminarily assigned an icon to the task.

Create the profile State -> Plugin -> AutoRemote with the Message field Filter copy=:= on device 2. By all means place a checkmark on Event Behaviour. For the task, select the action Misc -> Set clipboard and enter the variable %arcomm into the Text field (it contains text to the right of =:=).

Send setup on the sending device

Send setup on the sending device

Profile setup on the receiving device

Profile setup on the receiving device

 

Now after pressing the widget the first device will send the content of its exchange buffer to the exchange buffer of the second device. Similarly, many other things can be done. For example, having created a profile on one device, which sends the “reboot” word, and a profile on the second device, which operates according to this command and executed System-Reboot, it is possible to reboot the device. If it is possible to transfer the run app_name comamnd, and select App -> Launch App and the required program from the list for action on the second device.

EventGhost

We will need EventGhost for communication between devices and computer. It is a sort of Tasker for Windows, which allows to automate the operation of PC. It is free and open under GPLv2 as it is accessible to anybody for downloading and installation.

The program window consists of two parts: on the left — system logs and events, on the right — macros grouped into the so-called Configuration Tree (see 1.1 on the screenshot). All our further settings will just relate to the creation of new macros performing certain actions in reply to the events occurring. The main language of the program, Python, and many actions that are initially provided by the program can be performed by means of scripts and actions of the python commands. In order to insert finished macros given below, it is necessary to make a right click on Configuration Tree and select Paste in the menu, and then correct the macro according to your requirements.

Main window of EventGhost

Main window of EventGhost

 

Plug-ins

EventGhost has a rather long list of plug-ins, which significantly extend its capabilities. In order to install a third-party plug-in, it is necessary to transfer it to the “Program Files (x86)\EventGhost\plugins” folder and restart EventGhost. In order to provide that the plug-in should always be used, it is necessary to add it into Autostart. For the tricks to be described herein below, we will need the Keyboard plug-in for interception and emulation of button pressing events, Directory Watcher for tracking changes in folders and, of course, AutoRemote for communication with mobile devices.

AutoRemote plug-in

In order to install the plug-in, download file, place it in the plug-in folder (\EventGhost\plugins\AutoRemote), reboot EventGhost and the plug-in itself to the startup program group. Complete some lines in the pop-up window: add devices by completing the Device Name and Personal URL fields, which we obtained by installing AutoRemote on the devices. Device Key should be completed automatically when Tab is pressed. In addition, it is possible to send a list of devices from the telephone by coming into AutoRemote, then tap and hold EventGhost and select Send My Devices in the menu.

Setup of AutoRemote plug-in

Setup of AutoRemote plug-in

 

For the devices being aware of the fact that EventGhost is accessible for receiving commands, it is necessary to add the registration action into the Autostart branch: AutoRemote -> Register EventGhost and select a device in the pop-up window and repeat everything for remaining ones.

Tricks

Now we have everything that is necessary for creating configurations combining the capabilities of EventGhost and Tasker + AutoRemote. Most of the tricks given below consist of two components: an EventGhost macro, which determined the action (Event) and reaction to it (Action) as well as the Tasker profile, which performs similar tasks on the part of the smartphone. Being operated together, they allow to do a lot.

Sending files from a computer to a device

To perform sending it is necessary to insert the following code into EventGhost (right click on Configuration tree, then Paste):

<source lang="HTML"><?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1630">
<Macro Name="Send file" Expanded="True">
<Event Name="Main.SentFromExplorer.File" />
<Action>
    AutoRemote.SendMessage(u'Android Device', u'', u'', u'files', u'', u'', u'', '', u'{eg.event.payload[0]}')
</Action>
</Macro>
</EventGhost></source>

Then edit “AutoRemote: Sending files to Android Device” (double click by mouse) having selected the required device (see 1.4). At that nothing should be done on smartphone, AutoRemote will automatically receive and save the file. Sending is carried out via the explorer’s context menu.

However this method has one drawback. By default, it is possible to send a file only to one device selected in the plug-in settings. If it is required to send a file to several devices at once (telephone/tablet PC), one will have to correct the register: duplicate the value: C:\Program Files (x86)\EventGhost\EventGhost.exe -event SentFromExplorer.File “%1” in the branch HKEY_CLASSES_ROOT*\shell\SendToEventGhost with renaming the Item and adding a symbol before .File. Then the structure shown on the screenshot will be obtained. A video instruction is available on my channel.

Modified structure of the register

Computer turn-on notifications

Add Action -> AutoRemote Notification into AutoStart (see 1.5), select the required device and complete Title and Text. Now with computer start-up (of course, in case when Internet is active) the notification will come to the telephone. It is possible to adjust additional fields: vibration, sound, action when notification is pressed.

Notification on telephone in case of computer start-up

Notification on telephone in case of computer start-up

 

In fact, there are a large number of variants for using notifications. EventGhost can respond to virtually all system events and a notification can be linked with any of them. An example can be the user entry into a disabled computer. When it occurs, EventGhost will generate the System.SessionUnLock event. Create a macro for the second event and, as an action, copy the same AutoRemote Notification. Now we know that the computer was tampered when we were absent there (see 1.6).

Sending a text to telephone/tablet PC from any text editor

Insert the following code into Configuration Tree:

<source lang="HTML">
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1669">
  <Macro Name="Send clipboard to my device" Expanded="True">
    <Event Name="Keyboard.Ctrl+Alt+V" />
    <Action>
    AutoRemote.SendMessage(u'My Device', u'URL', u'device', u'copy=:={eg.WinApi.Clipboard.GetClipboardText()}', u'', u'', u'', '', u'')
    </Action>
  </Macro>
</EventGhost>
</source>

Change the device and the name into ours. Now any text copied can be sent to the device by pressing (see 1.13). Please note that the text will come as a message for AutoRemote, so at the device you will have to handle it by means of Tasker. Alternatively, insert into the exchange buffer (see at the beginning of the paper).

Sending a text to a computer from a telephone/tablet PC

As has been shown in the example from the “Tasker” section, create the action: Plugin -> AutoRemote Message, but select EventGhost in the Recipient field. The Message field will also remain as copy=:=%CLIP. For convenience, place the widget on the desktop. Insert the following code into Configuration Tree EventGhost:

<source lang="HTML">
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1669">
  <Macro Name="Copy to Clipboard" Expanded="True">
    <Event Name="AutoRemote.Message.copy" />
      <Action>
        EventGhost.PythonCommand(u'eg.WinApi.Clipboard.SetClipboardText(eg.event.payload.arcomm)')
      </Action>
  </Macro>
</EventGhost>
</source>

Now by pressing the widget, the text contained in the smartphone exchange buffer will be sent into the computer exchange buffer. For better visibility, one more Action — Show OSD can be added to the macro. OSD means On Screen Display, i.e. a text on top of all windows. It is possible to adjust the position, color, font, time of display, etc. As a notification, I will use: “The text is copied: {eg.event.payload.arcomm}”, where the expression in figure brackets corresponds to the text received (see 1.7). In the log (see 1.12), we can see the macro operation result, but it is in the log that the Russian text is displayed in Unicode.

Sending a file from telephone to computer

Another Tasker’s plug-in will be needed for operation, AutoShare, allowing to take all information into variables that is transmitted in using the Android standard Share menu: Send/Share. After installation, create the command “File to computer” by pressing + in Manage Commands. Create the profile in Tasker: State -> plugin -> AutoShare Command and select the required command. Then create the action: Plugin -> AutoRemote Message with the parameter: incoming=:=%asfile(), where %asfile() is an array with files selected for transmission. Enter %asfile() into the Files field. Insert the following code into Configuration Tree on the computer side:

<source lang="HTML"><?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1669">
  <Macro Name="Incoming Files" Expanded="True">
    <Event Name="AutoRemote.Message.incoming" />
    <Action>
      EventGhost.PythonCommand(u'print eg.event.payload.files[0]')
    </Action>
    <Action>
      System.Execute(u'C:\\Windows\\explorer.exe', u'/select,{eg.event.payload.files[0]}', 0, False, 2, u'', False, False)
    </Action>
  </Macro>
</EventGhost>
</source>

In case when a message is received which contains the “incoming” command, this macro will receive the file into the folder, which was indicated during setting the AutoRemote plug-in, after which the macro will open the explorer with the file name being highlighted (in the first place if there are several files), for which the /select parameter is responsible {eg.event.payload.files[0]}.

At the wish, it is possible to add Show OSD with the file name before it (A new file has been obtained: {eg.event.payload.files[0]}) or remove the last action at all (see 1.8). Now it is possible to send files from file managers, galleries, etc. via the Android standard menu “/Share”.

Automatic sending screenshots from a telephone to a computer (root and busybox)

Create a profile in the Tasker with the event: Event -> File -> File Modified. Instead of a file, select the folder with the screenshot (magnifying icon, then “press and hold” on the folder itself). For the action, select Script -> Run Shell and enter the command: busybox ls /storage/emulated/0/Pictures/Screenshots -ltr | tail -1 | awk ‘{print $NF}’. Below, in the same action, enter the variable into the Store output in field (in our case — %Test5). The file name will be written in this variable.

Setup for the Run Shell action

Setup for the Run Shell action

 

As the next action, do Task -> Perform Task and select the job from the list which should be created first. To this end, create the action: Plugin -> AutoRemote Message in the Task tab and select EventGhost as the target device. Enter incoming=:= into the Message field, and insert the path to the file + name in the Files name. It will be /storage/emulated/0/Pictures/Screenshots/%Test5.

In my case, this Task is named Send Screen; accordingly I have selected it in the Perform Task action. There is no need to adjust anything additionally in EventGhost (we have already created the “incoming” handler while tuning file sending from a telephone to a computer). In case of successful sending, we will see the notification as in Fig.2. In order to provide sending screenshots made in succession, it is necessary to set Run Both Together in Collision Handling of task settings.

Create the Open On PC command (or any other convenient command) in AutoShare. For the new profile, create State -> Plugin -> AutoShare and select the required command in the Command Filter field. As the action, select the same AutoRemote Message with EventGhost as the device and %astext as the text.

Now if the AutoShare Command is pressed in any program where it is possible to share a link (in mobile Chrome, it is : Menu -> Send”) and AutoShare Command -> Open On PC is selected in the list, then the given page will open on the computer automatically. In addition, the link can be transferred after pressing if the program asks: “What to use?” To this end, it is necessary to press Open Remotely. Select any device in the next window.

Opening a file on a computer

Create a macro with the “AutoRemote.Message.open” event, add a Python command “from os import startfile;startfile(eg.event.payload.files[0])”. Send files with the Open command from Tasker.

Synchronization of a folder on a computer with a smartphone

Directory Watcher traces the new files in a certain folder (Send2Nexus) and when they appear it will send them to the telephone at once into the folder to be adjusted in AutoRemote. For the action, the same sending that was described above is used (see 1.9, 1.10).

Device management from Linux

Unfortunately, there is no AutoRemote Client for Linux but we can use a connective: web interface + SSH for managing devices and Linux-machines via AutoRemote server. To this effect, we will need “curl”:

$ sudo apt-get install curl

We will also need SSH with the possibility of login into the machine via login:password without necessity of using SSH-keys. When both these conditions are met, start the next command in order to authorize our Linux-machine:

$ curl "http://autoremotejoaomgcd.appspot.com/registerpc?key=YOUR_KEY&name=NAME&id=ANY_UNIQUE_ID&type=linux&publicip=YOUR_PUBLIC_IP_OR_HOST_NAME&localip=$(sudo ifconfig eth0 | grep "inet addr" |awk '{print $2}' |awk -F: '{print $2}')"
  • YOUR_KEY — the key, see above;
  • NAME — that is how the device with Linux will be displayed on telephone;
  • ANY_UNIQUE_ID — any unique ID.

After execution of the command, a window will appear on the telephone with a query for login and password from the Linux machine. Then the work can be started. In order to send a message to the devices (all), it is sufficient to execute the following command:

$ curl "http://autoremotejoaomgcd.appspot.com/sendmessage?key=YOUR_KEY&message=СООБЩЕНИЕ"

The message will be received in the following form: linux=:= СООБЩЕНИЕ, so in order to provide its handling it is necessary to set linux=:= in creating the Tasker profile in the AutoRemote Message Filter field. The messages that have come from devices will be interpreted as Linux commands, whose output will come in the reply message. For example, if you send, via Tasker to the machine, the message: ls / (AutoRemote Message — select the content that we entered into the NAME_TO_APPEAR_ON_YOUR_PHONE first field of Device, enter ls / into the Message field), then in AutoRemote logs we will see a list of files in the root directory begining from linux=:=. By means of Tasker, it is possible to handle the reply in a certain manner.

Conclusions

The connective Tasker + AutoVoice + AutoRemote + EventGhost + plugins provides very many possibilities for automation, in particular, by voice: from power supply control and starting programs to control of various devices, video and audio players, projectors, devices on X10, etc. You must admit that it is a pleasure to perceive yourself a part of the future having said: “OK, Google, please turn off my home computer” — and the computer will turn off in several seconds. Or coming to your home you can say: “OK, Google, please start Watch Dogs.”


2 Responses to “Forged together with one chain”

Leave a Reply to SusanHansondut

Click here to cancel reply.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>