How often do we get engrossed with something on our mobile phones? It could be a passionate conversation with your buddy or another rabbit hole with dozens of links to follow. It often leads us to our computers and laptop to continue our exploration. If only there was a seamless way of transitioning the content of your mobile onto the computer without messing around with extra buttons. Something like a Smart Dock…
I will be honest with you guys, it only recently occurred to do this, even though I had everything needed in my previous Tasker projects, just not in this specific combination. The smart dock is a virtual concept. You can use any dock, phone holder or simply replace the trigger with something more suiting your needs.
I went with the dock, as Android 10 removed, a very much liked by me, custom icons from the navigation bar. I had an array of insanely useful actions, which became obsolete thanks to another Android update that curbed personalisation. The Navigation icon is still there in Android (enable Accessibility button to see it), but not available to us – common folk.
How does it work?
Tasker detects when the phone is docked (or put into a certain position) thanks to the relatively new sensors feature and sends the information about the application or page currently opened on your phone to an active computer. What’s an “active computer” you may ask? In case you have more than one device at home, Smart Dock can detect which computer to cast the information to.
You have the ability to define smart dock behaviour. It’s possible to detect various docks, pick applications that are cast to computers or even add operational hours if you want to personalise the behaviour further. In this project I will show you how to make it work with the 3 most common mobile use cases:
- web page
I mentioned YouTube separately, as resuming a specific video is slightly more complicated and requires a modified task. To make it all happen, you will need the following:
Smart Dock – the trigger
I have a Xiaomi Battery Dock (review), which I modded recently to make it truly wireless by cutting the cord off and replacing it with a USB-C port. It’s a perfect companion and my phone is often docked next to my computer. The phone starts wireless charging when it’s docked, and I can define the spatial orientation by pulling raw data from Tasker Sensor action. The naming convention for sensors may vary from phone to phone, try a couple of them responsible for orientation in 3D. I also tied that with Screen On, so I don’t have accidental triggers unnecessary.
If your dock has no charging, sensor data should be enough to detect the position. Feel free to experiment with extra conditions until you are happy with the result.
I covered this topic extensively in my other write up. If you want details, read that. In short, EventGhost is installed on each computer and it uses AutoRemote to send the information with the name of the computer whenever the system boots or stops idling. Tasker stores the name of the computer that had been used last in a variable %ACTIVEPC.
Smart Dock cast application to computer
Most of the apps will open as URL counterparts on a computer, but you can get more creative with it. When a compatible app is opened on your mobile, it sets a variable %APPCURRENT to its name. This is used by the main profile to determine what IF action Tasker will execute.
For each app, you will have to create a separate profile that sets the %APPCURRENT on entry and resets the value to none on exit. To open the associated URL on a computer, you have 2 choices:
AutoRemote + EventGhost
EventGhost has the ability to open web pages on your PC based on triggers from AutoRemote (more about AutoRemote). You can send a message to open a hardcoded in EventGhost URL, or specify the URL in Tasker and sent it from there.
Based on %APPCURRENT and target device (%ACTIVEPC) AutoRemote message is sent to EventGhost and executed. I picked the dynamic EventGhost profile as I can use it later with Chrome URLs. My AutoRemote message looks like this
URL=:=%CLIP (or fixed URL).
On the EventGhost side, a Python script is handing Chrome and opening the browser windows:
url = eg.event.payload.arcomm
chrome_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'
It's possible to do this without EventGhost, but you will lose the ability to set an active PC. Join has the ability to push an URL to another device, which will open it automatically. If you only have one computer, you will find the Join route easier.
URL Pushes for need a target device (%ACTIVEPC) and URL to push, which is hardcoded based on %APPCURRENT value:
and so on... In both cases, you will need either AutoRemote or Join extensions added to a Chromium based browser.
Smart Dock - Chrome URLs
Add Chrome (or whatever web browser you are using) to the list of apps that contribute their name to %APPCURRENT. Capturing URL is actually hard due to security concerns. You don't want to expose that natively to other apps you have on phone. This is where AutoInput comes in handy.
I use it more nowadays thanks to the ability to enable and disable the service as needed. To capture URL, AutoInput needs 2 actions: tap on the URL field then tap on "copy". If the downloaded profile isn't working for your browser, you need to re-teach these.
A copied URL is stored in %CLIP and can be easily sent to EventGhost via AutoRemote (optionally to Join). To display the page on your computer the EventGhost profile from the application section is used.
Smart Dock - YouTube
To make this work with YouTube, we have to change the AutoInput actions. I'm still going for the share option, but you could always take a look at Cast action and open the browser in a YouTubeTV mode instead or cast it to a smart TV or projector.
While Casting might be better for resuming the playback, my method only launches the video URL from the beginning. It's not ideal, but with a mouse at your disposal, finding the moment on the timeline where you left off is a minor inconvenience.
For YouTube, select share and then copy link action. By now you should feel very familiar with the process and how the URL will be handled.
I'm still sour over my NavBar actions not being used any more. I noticed that Tasker gained the ability to add Smart Home tiles into notification shade, which gave me a couple of ideas. Expect something along these lines soon. I hope you enjoy the project. Let me know what do you think in this Reddit thread.
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.