samedi 8 juillet 2017

Make your own Clipboard Manager with Tasker and AutoTools

For some time now, I have been trying to get around the issue of not having a clipboard manager on my phone. There are third-party applications and some keyboards that come with their own clipboard manager built in, but I personally find many third-party keyboards to be slow and clunky, therefore I generally stick with Gboard. Furthermore, I usually try to avoid installing a new application dedicated to one purpose if I can get away with it. This is where my very own Clipboard Manager made in Tasker comes to play!

Tasker – Clipboard Manager

Thanks to the new AutoTools WebScreens action, it is finally possible for me to create my own clipboard manager that is quick and easy to access. The Tasker Clipboard Manager project can store up to 9 clips, replacing old ones as new clips are added. I picked 9 items to store as they fit rather nicely on my screen, but with a few simple tweaks, you can set the number of stored clipboards to whatever you wish.

While you could have a floating action button (FAB) to pull up the clipboard, I prefer using a swipe gesture instead. To mitigate potential performance issues, I’ve set up the Tasker Clipboard Manager project to have a very small footprint on your phone’s memory as the profile can be limited to work with certain applications only. In the video down below, you can see me linking the clipboard menu to only the Google+ and Pages Manager applications. Bear in mind, though, that the collection of the clips occurs in the background anytime you make changes to the current stored clip.

If you are using the Join application, this project should not interfere with it. But by using Join, then you can also share selected clips from my project with your other devices. For this project, I’m using AutoTools WebScreens action so make sure you have the plugin installed. Anything else is just stock Tasker. Access to the clipboard manager is driven by the applications themselves. Thus, I don’t need this profile to be active when I’m watching YouTube or playing a game, so my profile is set to only activate on those applications that require it.

Here is a video showcasing my creation in action:

If you would like to import my project as-is, then you can do so by clicking the link below which will take you to the AndroidFileHost download page.

Download the above ZIP file and extract the contents onto the internal storage of your Android device. Open up Tasker and disable “Beginner Mode” in Preferences. Then, go back to Tasker’s main page and long-press on the home icon in the bottom left corner. You will see an option to “import” a project. Tap that option then find the .prj.xml file you extracted earlier. Once imported, you will see a new tab at the bottom alongside the default home icon in Tasker.

Take note that this project requires you to have AutoTools installed in order to work. If you would like to customize various aspects of my project, then I recommend you continue reading below so you have a handle on how this works and what changes can be made. Note that at the very least, you should change the applications in the Application Context so that this clipboard manager can be summoned in more applications than the default set I’ve made it active for.

PROFILE – Apps with Clipboard

In this example, I’m using Google+ and Pages Manager to enable the WebScreens swipe.

Select the applications you want to enable in the context then create a Task called Launch Menu. This task will enable the WebScreen swipe in the Tasker Project – Clipboard manager.

TASK – Launch Menu

In the AutoTools WebScreen option import a Screen preset (swipe) and remove all commands but ‘left‘ in the commands section of the setup page.

Set up the Window settings to your preference. I have the Gravity set to Bottom Right while the Width is 10 and Height is set to ‘fill‘.

TASK – Exit Clip Gesture

We need to disable the gesture when it’s not needed. Add an exit task and create another WebScreens action. This time use the Display Mode to set the ‘close‘ action. This will terminate the WebScreen and swipe recognition.

PROFILE – Show Menu

By default, swiping right will issue an AutoTools Command swipe=:=right. When this happens, I want my clipboard manager to open. Create a new Profile with the AutoApps context set to ‘swipe‘ as the filter. When the swipe is done, a nice menu will appear with all the clips we need.

TASK – Clipboard Menu

The layout has been ‘borrowed’ from Joao’s tutorial. I liked how the side launcher looked so there was no point in reinventing the wheel. Obviously, the variables used in that WebScreen will be different, but the layout is pretty much the same.

TASK - array numbers

Create this task then generate the array. This will create the global array.

PROFILE – Clipboard Monitor

This profile will monitor changes in the %CLIP system variable that contains the current clipboard value. Create a profile with the Event trigger Variable Set and set it to monitor for the variable %CLIP. When a new clipboard entry has been set by the user (you), Tasker will detect the change.

TASK – Clipboard Manager

Our clipboard content is stored in the %ClipboardArray(). Each time a new clipboard is saved, an Array Push (A2) action moves it to the 1st position of the array. Because I don’t want the entire text to be visible on the side menu, I created another array %ClipAbrev()(A3) that will store the first X letters of the clipboard. To shorten the clipboard, use (A1) Variable Selection and limit numbers of characters to 6 (make sure that Adapt to Fit is checked) and store that value in the local %abrev variable which is used to populate the (A3) Array Push action.

Now that we have the clipboard collection ready we have to clean up the mess. The array will collect all the clipboards. This means that when we pick a clipboard from our side menu, it will collect the new value and assign it as a duplicate to the menu. Therefore, each time we save a clip I want to remove duplicate entries (A4, A5) and remove empty spaces (A6, A7). Array process actions are performed on both %Clipboard Array() and %ClipAbrev().

Lastly, I want my menu to contain 9 entries only. You can have more, but I find that the 9 menus fit great on my screen without scrolling. To do this, use Array Pop (A8,A9) and remove the 10th position. Do this ONLY if the array contains 10 elements. Otherwise, the last element is removed. We achieve this by checking if the number of elements %ClipboardArray(#) = 10.

PROFILE – Set Clipboard

We are nearly done. This is a very simple profile. We are using the AutoApps command clipboard to check if the command has been received. The command will look like this: clipboard=:=1 where the number stands for the button pressed on our side menu.

PROFILE - Set Clipboard

TASK – Set New Clip

The task is very simple as well. Set the clipboard to the value of the %ClipboardArray() we want to choose the element specified by the %aacomm part of the received command. So set clipboard as %ClipboardArray(%aacomm) and you are done. The Tasker Clipboard Manager is now completed.

Now, within your selected applications, you can swipe right to open your own custom clipboard manager! Follow the XDA-Developers Tutorials feed for more posts such as this. Also, check out our Tasker Tips & Tricks forum for the latest creations among the automation enthusiasts in our community.