Tasker

Tasker Smart NavBar #1 Cast to active PC

This smart NavBar action uses an app as the context and casts the relevant information to an active PC. It’s most useful if you want to continue media consumption on the PC of your choice. This could range from opening web interfaces of the apps (Facebook, Messenger, WhatsApp, Chrome) to sending device-specific commands.

What do I mean by “active PC”? This is the computer that has been used recently. I will base my tutorial on ActivePC write-up, so read that up for more details. I will use two ways of detecting the target machine to support more options. In the nutshell, you can cast to the target PC based on:

  • location context (WIFI connected, when EventGhost can’t be used)
  • system.unidle (EventGhost enabled PC)

In this example, I will use the Facebook app as the context and www.facebook.com page to be opened on the target machine. An icon representing my laptop, desktop, and a work computer will display dynamically in the smarter NavBar. These will update based on the location and the last computer used.

Smart NavBar: Cast to active PC

EventGost watches system.idle and system.unidle events. These are created automatically when the computer is not used for 1 min or it’s woken up by an input device, respectively. The information which device is active is sent via AutoRemote to back to your phone. At any given time, Tasker knows which was the last used machine.

There is a minute cooldown associated with the idle messages being issued on the machines, so if you change your computer and return to the same machine, the status won’t be posted. You could fix that with some EventGhost magic from this write-up and your creativity.

Cast Facebook to active PC

The Tasker profile is simple, use Application context to show a new NavBar when Facebook is open. The NavBar contains the following configuration:

  • back[1.0]
  • home[1.0]
  • task(name of the task followed by active device variable)[1.0]

The Smart NavBar will contain the icon of the active PC and will run the task responsible for sending the information to the PC.

Tasker PROJECT: NB Facebook
Profile: NB Facebook 
	Application: Facebook
Enter: NB Open Facebook 
	
	A1: Navigation Bar [ Left:back[1.0] 
			     Center:home[1.0] 
			     Right:task(NB Facebook %ActivePC)[1.0] ] 
		If [ %DEVICELOCATION ~ home ]
	
	A2: Navigation Bar [ Left:back[1.0] 
			     Center:home[1.0] 
			     Right:task(NB Facebook WIFI)[1.0] ] 
		If [ %DEVICELOCATION !~ home ]
	A3: Variable Set [ Name:%NBactiveApp To:Facebook ] 

Exit: NB Reset 
	A1: Variable Set [ Name:%NBactiveApp To:none] 
	A2: Navigation Bar [ Left:back[1.0]
					 Center:home[1.0]
					 Right: ] 

I have created an Entry task which sets the variable %NBactiveApp to Facebook (needed if you going to have multiple apps) and assigns a correct NavBar. The exit task simply resets the NavBar to the default (back, centre, none) settings.

Device Location Profile

Because I promised the contextual control over PC’s that cannot run EventGhost, I can use also WiFi to override this profile. I will create another profile that sets the location to: home, work, or elsewhere. Once again, I will set the %DEVICELOCATION variable as this info can be used in different projects.

Tasker PROFILE: Device Location
Profile: Device Location 
	State: Wifi Connected [ SSID:* MAC:* IP:* Active:Any ]
Enter: Set Dev Locale 
	A1: Variable Set [ Name:%DEVICELOCATION To:home] 
		If [ %WIFII ~R SlowFrog|FastBerry ]
	A2: Variable Set [ Name:%DEVICELOCATION To:work] 
		If [ %WIFII ~R ITC UK ]
	A3: Variable Set [ Name:%DEVICELOCATION To:elsewhere] 
		If [ %WIFII !~R SlowFrog|FastBerry|ITC UK ]
Exit: WIFI reset
    	A1: Variable Set [ Name:%DEVICELOCATION To:elsewhere ]

The location logic will be as follows:

  • work (target my work PC)
  • elsewhere (target my laptop)
  • home (target the active PC)

If the phone is no longer connected the %DEVICELOCATION defaults to “elsewhere“.

Now that I have the location framework, I can use this to control the active PC profile.

Set Active PC Profile

Tasker PROFILE: Set Active PC
Profile: Set ACTIVEPC 
	Event: AutoRemote [ Configuration:activePC (regex) ]
Enter: Set Active PC 
	A1: Variable Set [ Name:%ActivePC To:%arcomm ]	

	A2: If [ %NBactiveApp ~ Facebook & %DEVICELOCATION ~ home ]
		A3: Navigation Bar [ Left:back[1.0] 
				     Center:home[1.0] 
				     Right:task(NB Facebook %ACTIVEPC)[1.0] ] 			
	A4: End If

I’d suggest sticking both profiles (Set Active PC & Device Location) into the “main” folder, as these can be referenced by other projects too! Especially, if you are interested in automating WhatsApp (coming soon).

Note that I have enclosed the Smart NavBar actions in IF statement, these actions are specific to Facebook action. I added the %DEVICELOCATION variable, as my dynamic options will only apply when I’m home. This way I can retain the information about the active PC without actually drawing a NavBar each time.

The active PC is stored in the variable %ACTIVEPC (if you want to know why in CAPS, read this article). Each time I change the computer, Tasker receives an AutoRemote message and updates the variable. To make my life less complicated, each computer name is taken from the Join App. I can use the verbatim spelling of the %ACTIVEPC variable to send messages to Join devices.

NB Facebook Laptop/Desktop/WiFi

Cast to active PC 8 - for some reason we don't have an alt tag here

The easiest way to update the icon in the NavBar was to create a duplicated task with the same action but different name and the icon.

Tasker TASK: NB Facebook Laptop/Desktop
NB Facebook Laptop 
	A1: Join Send Push [ Configuration:Url: https://www.facebook.com/
	      Device Name: %ACTIVEPC Timeout (Seconds):60 ] 
	A2: Flash [ Text:Sent to %ACTIVEPC  Long:Off ]
Cast to active PC 5 - for some reason we don't have an alt tag here

The location based task is slightly different and uses %DEVICELOCATION to set the correct Join push action:

Tasker TASK: NB Facebook WiFi
NB Facebook WIFI (51)
	A1: Join Send Push [ Configuration:
                Device: Laptop
		Url: https://www.facebook.com/
		 Timeout (Seconds):60 ] 
		If [ %DEVICELOCATION ~ elsewhere ]
	A2: Join Send Push [ Configuration:
                Device: Work
		Url: https://www.facebook.com/ Timeout (Seconds):60 ] 
		If [ %DEVICELOCATION ~ work ]
	A3: Flash [ Text:Done Long:Off ] 

In this case, the devices are hardcoded! Join Push messages are send based only on the %DEVICELOCATION taken from the Locale profile.

Smart NavBar integration

This is a stand-alone version of the Smart NavBar actions. Once I created the stand alone versions for each NavBar Task I will show you how to integrate it together. The link to that write up will be up soon!

Conclusion

Android NavBar is underutilised in my opinion, so it’s cool to add extra functionality without adding any additional menus. The contextual character of the NavBar means, that the action is there when you need it most. Next up, I will add extra smart NavBar actions to WhatsApp. You can download the standalone tasker project from here.

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Mat Zolnierczyk

I am passionate about technology, cycling, and art. This would explain why my bike has more computing power than your average office. I own notenoughtech.com and I write for xda-developers.com and pocketables.com NotEnoughTECH | Facebook | Twitter |YouTube |Instagram | Google+ |Donate |Patreon

Avatar of Mat Zolnierczyk