Hello all.
I used to use Swiftkey, but after several recent updates, accessing the clipboard manager was rather obnoxious. I moved to Gboard, especially after they added the automatic space after punctuation. The only thing Gboard didn't have that Swiftkey has that I missed was a clipboard manager with a history. Tasker to the rescue! I created a clipboard manager that maintains a 3 hour clipboard history (this can be changed) that you can copy from if you need an old clipboard snippet.
This project is inspired by the Read Later List project.
PREREQUISITES: You will need to have the AutoApps, AutoTools, and optionally the AutoNotification plugins for this project to work.
N.B. When describing the configuration of any actions, if I don't mention a field, leave it at its default value.
STOP. PLEASE READ!! Throughout this project, we'll be using a tilde (~) as our item separator in lieu of a comma in certain areas, as sometimes copied text contains a comma, which can throw off the entire JSON table. Please be aware of this if you are manually building the project.
The first task we're going to build is called "Reset Clipboard," a clear/reset of the JSON where the clipboard content will be stored. This will allow us to reset the table if something goes wonky, and initialize it for first use. The variables used here will be elaborated on further in the guide.
The first action is to clear the variable where the JSON is stored.
Next, we'll need to create a clean JSON that can be written to.Code (Text):A1: Variable Clear [ Name:%Clipboard Pattern Matching:Off Local Variables Only:Off ]
We'll then store the "clean" JSON in the variable cleared above.Code (Text):A2: AutoTools Json Write [ Configuration:Separator: ~
Json Input: %Clipboard
Add to Array Key: items
Array Object Keys: text~time
Array Object Values: %CLIP|%TIME
Arrays Separator: | Timeout (Seconds):60 ]
Run this task once to prepare the JSON table and its variable.Code (Text):A3: Variable Set [ Name:%Clipboard To:%clipboard Recurse Variables:Off Do Maths:Off Append:Off ]
Next, we'll need to build the profile that will actually take the clipboard's contents, and add them to the JSON. It is called "Add Clipboard Content To Clipboard Manager."
First, we'll need to read the JSON, and ensure that whatever we just copied isn't already in the clipboard manager already, so a duplicate entry isn't made. This is done using the value filter on the dynamic system variable "%CLIP."Code (Text):Event: Variable Set [ Variable:%CLIP Value:* User Variables Only:Off ]
Once we've ensured that this is a new snippet, we'll add it to the clipboard JSON.Code (Text):A1: AutoTools Json Read [ Configuration:Simple Mode: true
Json: %Clipboard
Fields: text(),time()
Filter Fields: text()
Filter Values: %CLIP
Contains All: true
Separator: , Timeout (Seconds):60 ]
Then, we'll write the JSON to a global variable.Code (Text):A2: If [ %text(#) ~ 0 ]
A3: AutoTools Json Write [ Configuration:Separator: ~
Json Input: %Clipboard
Add to Array Key: items
Array Object Keys: text~time
Array Object Values: %CLIP|%TIME
Arrays Separator: | Timeout (Seconds):60 ]
Next, we'll create the profile that purges old content out of the clipboard manager. I have it set to purge content older than three hours, but if you want to lengthen/shorten that, it can be done in step A4.Code (Text):A4: Variable Set [ Name:%Clipboard To:%clipboard Recurse Variables:Off Do Maths:Off Append:Off ]
The first step will to be to read the variable where the JSON is stored.Code (Text):Profile: Purge Old Clipboard Content (223)
Time: Every 1h
We'll need to grab the current system time, and put it into a variable we can modify so we can compare against it to purge old content. We'll then grab just the hour section, and modify the variable to contain just that.Code (Text):A1: AutoTools Json Read [ Configuration:Simple Mode: true
Json: %Clipboard
Fields: text(),time()
Separator: , Timeout (Seconds):60 ]
This is the step where you can modify how long you want to keep content. Just modify the subtraction value to however many hours you want to keep content.Code (Text):A2: Variable Set [ Name:%purgetime To:%TIME Recurse Variables:Off Do Maths:Off Append:Off ]
A3: Variable Section [ Name:%purgetime From:1 Length:2 Adapt To Fit:Off Store Result In: ]
Because Tasker keeps time in 24 hour format, we'll want to modify it to perform the comparison easier.Code (Text):A4: Variable Subtract [ Name:%purgetime Value:3 Wrap Around:23 ]
Now, you'll need to do a loop through every item in the JSON to compare it against your PurgeTime to see if it's eligible to be purged.Code (Text):A5: If [ %purgetime > 12 ]
A6: Variable Subtract [ Name:%purgetime Value:12 Wrap Around:0 ]
A7: End If
If it is, then the content will be removed from the JSON.
Ok. So we have all this backend stuff that's adding snippets to the clipboard, and automatically purging it after a set time. How do we actually view and interact with the content? With just one, simple (haha, not really) command!Code (Text):A8: For [ Variable:%time Items:%time() ]
A9: Variable Section [ Name:%time From:1 Length:2 Adapt To Fit:Off Store Result In:%calctime ]
A10: If [ %calctime > 12 ]
A11: Variable Subtract [ Name:%calctime Value:12 Wrap Around:0 ]
A12: End If
A13: If [ %calctime < %purgetime ]
A14: AutoTools Json Write [ Configuration:Separator: ~
Json Input: %Clipboard
Prettify: true
Delete Paths: items.time
Delete Values: %time
Exact: true
Arrays Separator: | Timeout (Seconds):60 ]
A15: Variable Set [ Name:%Clipboard To:%clipboard Recurse Variables:Off Do Maths:Off Append:Off ]
A16: End If
A17: End For
Normally, I'm not one to create named tasks, and just create ad hoc tasks. In this case though, we'll want to create a task called "Show Clipboard Manager" that we can reference in a couple different places.
First, we'll want to read the JSON to get its content to display.Code (Text):Show Clipboard Manager
We'll want to join all the clipboard snippets into a single variable to make it easier to read and act upon.Code (Text):A1: AutoTools Json Read [ Configuration:Simple Mode: true
Json: %Clipboard
Fields: text(),time()
Separator: , Timeout (Seconds):60 ]
If there's nothing in the clipboard manager, we'll show a simplified window that states as much.Code (Text):A2: Variable Join [ Name:%text Joiner:~ Delete Parts:Off ]
If there is actually content to display, we'll want to show it!Code (Text):A3: If [ %text(#) ~ 0 ]
A4: AutoTools Web Screen [ Configuration:Screen Preset: Card List
Display Mode: Overlay
Source: /storage/emulated/0/AutoTools/cardlist/page.html
Toast Duration: 5000
Width: 300
Height: 130
Gravity: Center
Animation: Zoom In
Show Duration: 500
Hide Duration: 250
Drag: Not Draggable
Close Button: Top Right
Close On Command: true
Search Color: #ffffff
Filter With Search: true
Command Prefix: search
Drawer Width: 80%
Card Titles: Clipboard history is empty.
Card Buttons: Close
Accent Color: #01579B
Max Card Widths: 90%
Min Card Widths: 90%
Title Text Size: 20
Subtitle Text Size: 22
Card Padding: 10
Card Alignment: Center
Item Separator: , Timeout (Seconds):30 ]
Now, we'll need to configure the buttons on each card allowing you to either add the snippet to your current clipboard, or manually remove it from your list.Code (Text):A5: Else
A6: AutoTools Web Screen [ Configuration:Screen Preset: Card List
Display Mode: Overlay
Source: /storage/emulated/0/AutoTools/cardlist/page.html
Toast Duration: 5000
Width: 300
Height: 360
Gravity: Center
Animation: Zoom In
Show Duration: 500
Hide Duration: 250
Drag: Not Draggable
Close Button: Top Right
Wait For Command: true
Title Icon: android.resource://net.dinglisch.android.taskerm/hd_content_new_event
Title Button Commands: ResetClipboard
Search Color: #ffffff
Filter With Search: true
Command Prefix: search
Drawer Width: 80%
Card Titles: %text
Card Buttons: Copy~Remove
Accent Color: #01579B
Max Card Widths: 90%
Min Card Widths: 90%
Title Text Size: 20
Subtitle Text Size: 22
Card Padding: 10
Card Alignment: Top
Item Separator: ~ Timeout (Seconds):30 ]
Now we need to create a profile that calls the action we just built to show the clipboard manager itself. This is based on calling an AutoApps command.Code (Text):A7: If [ %atcommand Set ]
A8: If [ %atcommand ~ *=:=Copy ]
A9: AutoTools Web Screen [ Configuration:Display Mode: Close
Toast Duration: 5000
Height: 400
Gravity: Center
Animation: Slide In From Top
Show Duration: 500
Hide Duration: 250 Timeout (Seconds):30 ]
A10: Variable Search Replace [ Variable:%atcommand Search:=:=Copy Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A11: Set Clipboard [ Text:%atcommand Add:Off ]
A12: Flash [ Text:Copied! Long:Off ]
A13: Else If [ %atcommand ~ *=:=Remove ]
A14: Variable Search Replace [ Variable:%atcommand Search:=:=Remove Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A15: AutoTools Json Write [ Configuration:Separator: ~
Json Input: %Clipboard
Prettify: true
Delete Paths: items.text
Delete Values: %atcommand
Exact: true
Arrays Separator: | Timeout (Seconds):60 ]
A16: Variable Set [ Name:%Clipboard To:%clipboard Recurse Variables:Off Do Maths:Off Append:Off ]
A17: AutoAppsHub SendCommand [ Configuration:Command: ClipboardManager Timeout (Seconds):60 ]
A18: End If
That's all you need! An additional optional step you can do is create a quick action tile to easily access your clipboard from anywhere. If you don't want to do this, you do not need the AutoNotification plugin, and you can be finished now!Code (Text):Profile: Show Clipboard Manager (226)
Event: AutoApps Command [ Configuration:Command Filter: ClipboardManager ]
Enter: Show Clipboard Manager (219)
This is a fairly simple task. I am only using tile number 4 as I'm already using the other tiles for other projects.
And there you go! You now have a self-purging clipboard manager that you can access and copy from any screen! Please let me know if you have any questions, and I'll be happy to answer them!Code (Text):Clipboard Manager Tile (225)
A1: AutoNotification Tiles [ Configuration:Tile: AutoNotification 4
Command: ClipboardManager
Label: Clipboard Manager
Icon: android.resource://net.dinglisch.android.taskerm/hl_ab_content_paste
State: Active
Hide Notifications: true Timeout (Seconds):60 ]
-Crepusculi
Self-purging Clipboard Manager/History Overlay 1.0
Create an overlay that contains your clipboard contents from the past 3 hours accessible anywhere