How to create a pop-up settings box using Tasker
One of the things I have on my phone’s homescreen is a tiny invisible icon that when pressed brings up a small pop-up overlay that has a slider and preset buttons for screen brightness. I love it, but I wish that it could do more than just handle brightness. As I knew that Tasker is capable of recreating its functionality and improve upon them, that’s what I set up to do. Read on to see where that took me, and what I did to get there.
Making a shortcut open a scene
I started by creating a new scene. A Tasker scene is basically a custom user interface element, like a pop-up box. I didn’t add any buttons at first, just needed the scene to be there to reference it elsewhere.
Then I headed to the Task tab and created a new task. Its only action right now is to open the scene I just created, done with the Show Scene action. Since this is a pop-up box the best choice for its Display As attribute is Dialog, Blur Behind, meaning that it blurs the background, pops up, and is the only screen element you can interact with while it’s there. You can also hide it by simply going back, even if we’ll try to avoid actually doing that – I’ll explain why later. Tasker can actually be used to add new buttons to existing apps (!) using some of the other Display As options, which can’t be hidden with the back button and will only allow you to interact with parts of the screen that it’s not directly covering. If you’re doing this yourself you need to make sure you have this option set right, as you’ll also want to uncheck Show Exit Button, and you don’t want to do that if the wrong Display As option is selected.
Fially I went to the home screen, selected to add a shortcut, and used the Task Cut shortcut to add a shortcut to run the Show Scene task. Icon and name doesn’t matter as in the end it will be invisible anyways. With this set up, clicking the icon at this stage brings up a blank scene box that can be removed with the home/back button, like you’d expect.
Adding the scene elements
The first thing I wanted to add to the pop-up box was a display brightness slider. After looking up a few things in the Tasker manual I discovered how to do it «properly». Go to the scene edit screen, make sure the magnifying glass icon is checked (edit mode), and click the + sign and sleect Slider. Create a name for it, set Min to 0 and Max to 255. Show Indicators will show these numbers never/always/while changing, your choice. Jump to the Value Selected tab, click the +, select Display, Display Brightness. Click what looks to be a refresh icon by the Level field to change it to a text input field. Write in %new_val in the field, ok your way out of it all and position/size the slider as you want. The slider now sets the screen brightness, but it needs one more tweak to make sure it starts at the current brightness level when the pop-up opens.
Head back to the task you created to show the scene, and add a new Variable Set action. Name it something unused (mine’s called %Brait) and set it to %BRIGHT. This simply transfers the info from the built-in current brightness level variable to a custom, user-made variable. Now add a Element Value action from the Scenes submenu, select your scene from the list, select your slider (it should auto-select), abd use tghe baggage tag icon to browse to your recently created variable, in my case %Brait. There seems to be a bug with Tasker that prevents you from inputting a variable manually, or even pasting its name, in the Value field here, at least I found no way of doing it. That’s why we “converted” the %BRIGHT valuable to one that isn’t built in, to allow it to be selected using the variable selector.
OK your way out of everything and try it outThese two newly added actions should now ensure that the slider’s starting position upon opening the scene matches the current brightness level.
While I said above that we’re using a scene type that can be hidden with the back and home buttons, I would recommend adding a button that does it the proper way: using Destroy Scene. You’d think Hide Scene is the way to go, as Destroy Scene sounds like it will delete you work, but in reality Hide Scene is like minimizing and Destroy Scene is like closing an app. We don’t want our pop-up menu to run in the background for no reason, which is what will happen if you just back out of it. The other elements added later all do this automatically when pressed as those are buttons, but a slider is unique in that it’s there for you to slide along and see what fits best, so having the thing disappear based on some automated system isn’t going to do it.
Adding this button is simple, just click the + symbol, select a button, confiure the name and label (label being what the button says), switch to the Tap tab, and add a Destroy Scene action.
I wanted roughly the same system of buttons as the pre-made pop-up I was using, but with some changes. Smaller buttons for one, and no auto brightness. I started off by making one button, naming it 0%, giving it a 0% label, and tweaking it the way I wanted it. In the tap tab I added two actions: Display Brightness Level 0 and Destroy Scene. The result is that when the button is pressed, brightness is set all the way down and the pop-up menu goes away.
With this one button all done I copied and pasted it four times, and changed the values that needed changing for each one. Basically that meant changing the name, label, and Level value of the Display Brightness actions. After doing this and placing the buttons, I had buttons for 0, 25, 50, 75, and 100% brightness.
At this point I basically had a slightly visually different version of the thing I had already been using. On to adding new stuff.
I’ve been meaning to add manual profiles to my phone for a while. I have my Outside profile and my Sleep Mode, but those are automated and complicated respectively. I knew that there were at least two other profiles I wanted to have access to, with the option to add more later of course. Those profiles were movie (cinema) mode and silent mode. Essentially both turn the phone to silent, but movie mode also turns down the screen brightness so I can check my phone in the movie theatre without it lighting up the whole room. It also writes a status to my Dropbox status text file which I’ve mentioned in other contexts before, adding the fourth possible state that system now has: Andreas is at the movies.
There are several ways of doing this but I decided to use Tasker profiles triggered by different values of the same variable, %Profile. By making different profiles activate on different values of the same variable, that ensures they can’t be both on at once.
Making the profile was simple. In Tasker’s profile screen I created a new profile, called it Movie Mode, and set the context to be Variable Value: %Profile matches «Movie Mode». Using such a «complicated» value rather than simple numeric ones will have its use later on, you’ll see. As actions, I added the three mentioned above. I then basically did the same for Silent Mode, but with only one action. Normal mode doesn’t need a profile, for its feature is simply that the other ones aren’t running when the variable is set to it.
Back in scene creationI added buttons for the three modes much the same way I did the brightness settings, but instead of the actions being Display Brightness + Destroy Scene these are Set Variable + Destroy Scene. The variable they set is %Profile to Normal mode, Silent mode, or Movie mode.
Finally I added simple text as a header to the profile buttons. The Text is set to Profile: %Profile which basically displays the word Profile and the currently active mode. This is the reason why I used “complicated” variable values, as I can then just pull that right into the header. I could also set up Sleep Mode and my Outside profile to modify this header, but I think I’ll leave those out of it as Outside is automatic and I’m not tinkering with profiles while Sleep Mode is on anyways.
URL to text file input field
This is something no one has any use knowing the full rundown of because it ties directly into my most advanced Tasker task system, which essentially creates a list of all articles I write and parses the number of articles in the current month to my Make Your Clock widget. The main system ties into custom PHP files on a server and Tasker tasks with close to 100 actions, so it would only serve to confuse. Point is, it works. However, the automation works only with WordPress sites, so I need a manual input for the rare time I write somewhere that isn’t WordPress. Until now, I’ve had a shortcut-triggered icon to do this, but I wanted to encorporate it into this pop-up box. While the exact tasks won’t be useful to anyone in this case, I do have some important tips to share about the use of Tasker’s TextEdit scene element.
The TextEdit scene element is basically a text input box. Getting it to do what I want took a bit of reading and testing. Basically you add actions to the Text Changed tab when configuring it to decide what happens. Any action in that tab will run every time you input text, and by that I mean for each letter. Type 123456789 and it will run the actions 9 times. Type 123456789 and then use backspace to clear and it will run 18 times. Point being, this is not where you want to have any major tasks like writing to files, unless you want your phone writing a file 18 times to write and then delete a 9 letter word you typed as a mistake. Instead, what you want to do is transfer the internal stock variable %new_val‘s content to your own variable. You do this by adding a Set Variable action, come up with a new global (minimum one capital letter) variable name (e.g. %Inputurl), and set it to %new_val. It will then overwrite this variable each time you type in a letter, but since only the last iteration will be left standing, the result is that the new variable will contain the finished input.
With the info transferred to a new global variable, you can use that in other elements. For me, I wanted a save button to trigger the actual save to file task when I’m done inputting a URL in the text box. I added a new button just like before, and went to its Tap tab. The first action I added was Task – Stop and added an If condition that %Inputurl matches *Inputurl*. This condition is true when you press Save without having entered any text, in which case %Inputurl has been cleared by the Variable Clear action at the end of the last time the task was run and Tasker has a “bug” which parsed variables with no data as the actual variable name. Alternatively I could not clear the variable after every time the Save button completes its task, but then you could click Save the next time it opens and actually write the same info to the file all over again – not good. In other words, this is a safety feature.
The next actions are actions that have to do with my setup, namely flash a confirmation and write the actual file, then run a separate multi-action task to update the widget. This is where you would substitute your own actions and use the variable which in my case is called %Inputurl to parse info from the TextEdit box to something else. An example would be a quick SMS creator for a pre-configured number, like your wife, where you just enter text in the box and click a button named Send. This would then use the Send SMS feature with your equivalent of %Inputurl as the text.
Finally, you have Variable Clear and Destroy scene, which are essentially the “close dialog box and reset for next time” actions.
Tesla LED toggle
The final thing I added to my pop-up was a toggle button for TeslaLED, the app I use to turn on/off my phone’s camera LED for use as a flashlight. I normally only access it using a toggle switch on my WidgetLocker lock screen, but that’s sometimes annoying if I have to unlock the phone to get to it. Luckily TeslaLED can be controlled with Tasker, meaning I can add an on, off, or toggle action to anything in Tasker. In this case, I added a button with no label, used a lightbulb icon from one of the downloadable Tasker icon packs instead, and as the Tap action I used TeslaLED toggle. Toggle means the same button switches it off and on, and not having a Destroy Scene action as well means the pop-up doesn’t disappear when clicking the button, a conscous choice to avoid needing the flashlight for 2 seconds and ending up going back into the pop-up for each toggle. Instead, the slider’s Ok button works just as well for this.
That’s all the features I added to my Brightness Level replacement for now. You can see the before and after shots above, with the before image showing the Brightness Level app’s version of this type of menu and the after shot showing what I just made in Tasker. They work the same: where I used to click an invisible icon over the battery widget to bring up the Brightness Level box, I now click an equally invisible button in the same place to bring up my box. The difference is I think mine looks better, it has more features, got rid of some stuff I didn’t need, and unlike Brightness Level, it doesn’t leave Brightness Level or anything else extra running in the background after it has been used thanks to the Destroy Scene implementation. Another day, another use for Tasker.