Nova Launcher and Tasker digital wellbeing tricks

I’m new to Nova Launcher, so don’t hate me if you already know about this. I switched to the launcher a couple of days ago, as I couldn’t get used to the native MIUI way of storing apps (no app drawer) on my new Xiaomi Mi9. After poking about inside Nova Launcher settings I found a really neat option!

Nova Launcher shortcut for apps and Tasker tasks.

What I’m referring to is a Nova Launcher gesture shortcut for folders. That’s right, you can perform a “swipe up” gesture on a folder to do its own thing. And this is rather brilliant. Here are cool things you can do with it!

In all honesty, all I wanted was a simple tutorial, but after 4 iterations I have a rather complicated looking contraption to explain in Tasker, but dead easy to use.

Favourite App in the folder

You can link the Nova Launcher shortcut with a “default app” for your folder. For this, you won’t even need Tasker. I have a “camera” folder, where I store the camera app shortcut and all my photo apps. It’s handy but to access the photo gallery I have to open the folder and select the correct app in the folder. Now, I all I have to do is to swipe up to achieve the same effect (the camera app opens with a designated button).

Create a folder (name it – optional). Long press on it to see the “edit” option.

In the folder options, select the swipe action and pick the application from the list. DONE!

Digital Wellbeing info with Tasker

Digital Wellbeing is a thing, whether we like it or not! You can track the app use in the latest iterations of Android but the option is buried in menus. I thought it would be cool to get simple usage stats for each app in the folder! Since the time conversion has proven to be a task on its own, I wrote about it more in a separate post.

This profile does just that:

  • Displays daily app usage data
  • Displays monthly app usage data
  • Uses dynamic values for the timer
  • You can monitor any app you want
  • Assign custom sort for each folder

Unfortunately, there is no clever way of getting the information of the app use (or at least, I’m yet to come across it!) so for now, I have to do this manually. My 1st iteration had a profile for every app, since then, I went full PRO and made it even more complicated impressive.

Getting the usage stats

I can calculate how long an app is open for, by creating a timestamp when the app is opened and closed. Then with a simple maths calculate the number of seconds elapsed.

These will be added to %MST (Monthly Stats) and %DST() (Daily Stats). Then I can use the Seconds to DD:HH:MM:SS tutorial to get that information flashed briefly on your screen.

Task – App Index

TASKER TASK: App Index
App Index
	A1: Array Set [ Variable Array:%AppIndex 
				Values:Facebook,Instagram,Twitter 
				Splitter:, ] 

I need an array %AppIndex() which will hold the names of the apps I want to monitor. You have to reference at least one (the profile is set to add new ones as you go) to get started, so use Array Set action to do that.

This task has to be run just once. Please note if you run the reset task Setup, it will wipe all the values not specified in the Array Set action.

Task – App Folder *(Social Folder)

TASKER TASK: Social Folder
Social Folder 
	A1: Variable Set [ Name:%index To:2,3,4 
			Recurse Variables:Off 
			Do Maths:Off Append:Off 
			Max Rounding Digits:3 ] 
	A2: Perform Task [ Name:CalculateStats 
			Priority:%priority 
			Parameter 1 (%par1):%index 
			Parameter 2 (%par2): 
			Return Value Variable: Stop:Off ] 
    

Each Nova Launcher folder has its own swipe up action, so for each folder you want to monitor this way you have to create a task. I called mine: Social Folder, as I will monitor the use of social media.

For each folder, specify the %index variable. It should be set as numbers separated by “,” (comma) and the numbers should correspond with app names stored in %AppIndex. The order of the numbers will define the apps and their order in the usage monitor window:

%AppIndex = (Facebook,Twitter,Instagram)
%index = 2,3  displays stats for Twitter and Instagram
%index = 3,1  displays stats for Instagram and Facebook

Profile – App Stats

TASKER PROFILE: App Stats
Profile: App Stats 
	Application: Facebook, Twitter, Instagram...
Enter: AppStats+ 
	A1: App Info [  Package: Ignore Packages: Ignore Unlaunchable Apps:Off Get All Details:Off ] 
	A2: Variable Set [ Name:%AppTemp To:%app_name 
			Recurse Variables:Off Do Maths:Off 
			Append:Off Max Rounding Digits:3 ] 
	A3: Variable Set [ Name:%index To:%AppIndex(#?~R%app_name) 
			Recurse Variables:Off Do Maths:Off 
	Append:Off Max Rounding Digits:3 ] 
		A4: If [ %index eq 0 ]
		
		A5: Array Push [ Variable Array:%AppIndex 
				Position:1 Value:%app_name Fill Spaces:Off ] 
		
		A6: Array Push [ Variable Array:%DST 
				Position:1 Value:0 Fill Spaces:Off ] 
		
		A7: Array Push [ Variable Array:%MST 
				Position:1 Value:0 Fill Spaces:Off ] 
		A8: Array Push [ Variable Array:%AppStart 
				Position:1 Value:%TIMES Fill Spaces:Off ] 
		A9: Stop [ With Error:Off Task: ] 
		A10: End If 
	A11: Array Pop [ Variable Array:%AppStart 
			Position:%index To Var: ] 
	A12: Array Push [ Variable Array:%AppStart 
			Position:%index Value:%TIMES Fill Spaces:Off ] 

Exit: AppStats- 
	A1: Variable Set [ Name:%app To:%AppTemp 
			Recurse Variables:Off Do Maths:Off 
			Append:Off Max Rounding Digits:3 ] 
	A2: Variable Set [ Name:%index To:%AppIndex(#?~R%app) 
			Recurse Variables:Off Do Maths:Off 
			Append:Off Max Rounding Digits:3 ] 
	A3: Variable Set [ Name:%stop To:%TIMES - %AppStart(%index) 
			Recurse Variables:Off Do Maths:On 
			Append:Off Max Rounding Digits:1 ] 
	
	A4: Array Pop [ Variable Array:%MST 
			Position:%index To Var:%mtemp ] 
	A5: Variable Set [ Name:%add To:%mtemp+%stop 
			Recurse Variables:Off Do Maths:On 
			Append:Off Max Rounding Digits:3 ] 
	
	A6: Array Push [ Variable Array:%MST 
			Position:%index Value:%add Fill Spaces:Off ] 
	
	A7: Array Pop [ Variable Array:%DST 
			Position:%index To Var:%dtemp ] 
	A8: Variable Set [ Name:%dadd To:%dtemp+%stop 
			Recurse Variables:Off Do Maths:On 
			Append:Off Max Rounding Digits:3 ] 
	
	A9: Array Push [ Variable Array:%DST 
			Position:%index Value:%dadd Fill Spaces:Off ] 
	A10: Variable Clear [ Name:%AppTemp 
			Pattern Matching:Off Local Variables Only:Off ]   
    

To monitor the usage of each app, select all the apps that you are interested in. When the app is opened, it will get identified, %AppIndex updated and stats measured even if you don’t display it in the folder.

Yes, this means that even if you delete the folder, you won’t lose the usage stats and you can bind it to other folders too!

Task AppsStats+

To identify which app triggered the profile, I use App Info action and check %app_name against the values stores in %Appindex array %AppIndex(#?~R%app_name). The result is the index number of the array where the app is stored.

To save the start timestamp, I need to pop the relevant element form %AppStart(%index) out to make space for the new value to push without ruining the order in the array. I also need the app name in %AppTemp for the exit task.

If the result of my array search is 0…

IF %index < 0

If you want to monitor an app which isn’t properly set up, this condition will push the new name of the app to the %AppIndex array on 1st position and shift the %DST, %MST and %AppStart values one up.

Task AppsStats-

Upon exit, I need to grab another timestamp and calculate the number of seconds the app had been opened for. But first, I need to know where I’m going to put it.

Since I stored the name of the app in %AppTemp I can search again %AppIndex to find out where I should store the app (%index). Then you can calculate the time with: %TIMES - %AppStart(%index)by recalling the starting timestamp from the %AppStart array.

The raw number of seconds is pushed simultaneously to %DST and %MST arrays which are responsible for storing the total number of seconds per Day and Month respectively.

Day Stats

To update the day value, I have to remove the existing value with a pop action and store it as %dtemp and add the current session by %dtemp+%stop, then push it back to %DST() array. Note that I already know where I’m sending all the data thanks to the %index.

Month Stats

To update the month value, I have to remove the existing value with a pop action and store it as %mtemp and add the current session by %mtemp+%stop, then push it back to %MST() array. Note that I already know where I’m sending all the data thanks to the %index.

Task – Calculate Stats

TASKER TASK: CalculateStats
CalculateStats 
	Abort Existing Task
	A1: Variable Set [ Name:%FolderArray To:%par1 
			Recurse Variables:Off Do Maths:Off 
			Append:Off Max Rounding Digits:3 ] 
	A2: Variable Split [ Name:%FolderArray Splitter:, Delete Base:On ] 
	
			A3: For [ Variable:%loop Items:%FolderArray() ] 
			A4: Variable Set [ Name:%display_app To:%AppIndex(%loop) 
						Recurse Variables:Off Do Maths:Off 
						Append:Off Max Rounding Digits:3 ] 
			
			A5: Perform Task [ Name:Calculate Time JS 
						Priority:%priority 
						Parameter 1 (%par1):%DST(%loop) 
						Parameter 2 (%par2): 
						Return Value Variable:%timed Stop:Off ] 
			
			A6: Variable Set [ Name:%display_timed To:%timed 
						Recurse Variables:Off Do Maths:Off 
						Append:Off Max Rounding Digits:3 ] 
			
			A7: Variable Set [ Name:%displayd To:%display_app:   %timed
						Recurse Variables:Off Do Maths:Off 
						Append:On Max Rounding Digits:3 ] 
			A8: End For 
	
			A9: For [ Variable:%loop Items:%FolderArray() ] 
			A10: Variable Set [ Name:%display_app To:%AppIndex(%loop) 
						Recurse Variables:Off Do Maths:Off 
						Append:Off Max Rounding Digits:3 ] 
			
			A11: Perform Task [ Name:Calculate Time JS 
						Priority:%priority 
						Parameter 1 (%par1):%MST(%loop) 
						Parameter 2 (%par2): 
						Return Value Variable:%timem Stop:Off ] 
			
			A12: Variable Set [ Name:%display_timem To:%timem 
						Recurse Variables:Off Do Maths:Off 
						Append:Off Max Rounding Digits:3 ] 
			
			A13: Variable Set [ Name:%displaym To:%display_app:   %timem
						Recurse Variables:Off Do Maths:Off 
						Append:On Max Rounding Digits:3 ] 
			A14: End For 
	A15: Flash [ Text:Daily Usage %displayd Long:On ] If [ %displayd Set ]														
	A16: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] If [ %displaym Set ]
	A17: Flash [ Text:Monthly Usage %displaym Long:On ] If [ %displaym Set ]    

For a strange reason, I cannot use %par1 directly in my FOR loop, but if I split the %FolderArray set to %par1 to get %FolderArray() the loop seems to be working ok!

Day|Month loop

Both loops work in the same way, I just draw the information from different arrays (%DST() & %MST()). First, I take one of the values assigned to my loop and read it the app name from %AppIndex(%loop), then I take the number of seconds and perform the seconds to DD:HH:MM::SS conversion (I used the JavaScriplet specifically as I have enough of nested tasks as is). I assign the return value to (%display_timed or %display_timem) variable and format it with the last action (remember to add Enter at the end to have a list view).

Profiles Daily|Monthly Reset

TASKER PROFILE: Daily Reset
    Profile: Daily Reset 
    	Time: 12:00AM
    Enter: Clear Day Stats (
    	A1: Variable Clear [ Name:%DST* Pattern Matching:On Local Variables Only:Off ] 
    	A2: Variable Set [ Name:%count To:1 
			Recurse Variables:Off Do Maths:Off 
			Append:Off Max Rounding Digits:3 ] 
    	A3: For [ Variable:%loop Items:%AppIndex() ] 
			A4: Array Push [ Variable Array:%DST 
					Position:%count 
					Value:0 F
					ill Spaces:Off ] 
			A5: Variable Add [ Name:%count Value:1 Wrap Around:0 ] 
    	A6: End For 
        
TASKER PROFILE: Monthly Reset
Profile: Monthly Reset 
	Day: The 1st
Enter: Clear Month Stats 
	A1: Variable Clear [ Name:%MST* Pattern Matching:On Local Variables Only:Off ] 
	A2: Variable Set [ Name:%count To:1 
		Recurse Variables:Off Do Maths:Off 
		Append:Off Max Rounding Digits:3 ] 
	A3: For [ Variable:%loop Items:%AppIndex() ] 
			A4: Array Push [ Variable Array:%MST 
					Position:%count 
					Value:0 
					Fill Spaces:Off ] 
			A5: Array Push [ Variable Array:%AppStart 
					Position:%count 
					Value:0 Fill 
					Spaces:Off ] 
	A6: Variable Add [ Name:%count Value:1 Wrap Around:0 ] 
	A7: End For
    

To reset the stats, I need two more profiles. One to clear the relevant variable at midnight and one to do it on the 1st of each month. For the day stats, I need to clear %DST* and set 0 value for each app that is monitored.

I can simply loop through elements of %AppIndex and push 0 value iterating the index number each time.

The same applies to monthly reset, but it’s performed on %MST* instead.

Conclusion

I’m well aware that most of you will jump to the bottom of the screen as going through this all, well it’s slightly insane. I guess I’m not 100% OK! It’s an excellent opportunity to join the Patreon as one of the perks is to get your hands on the projects like this one 3 day early.

I still love Pixel launcher, but looks like Nova Launcher will be the next best thing! Oh, I know I could use social total, but I’m past 2000 words already and I need a coffee! You can download the complete project from this link.

If you like my work you can always buy me a coffee or support me via Patreon.

Liked it? Take a second to support Pocketables on 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