Know Source of clipboard text

Post your questions and help other users.

Moderator: Martin

Post Reply
Graham
Posts: 7
Joined: 28 Dec 2013 16:19

Know Source of clipboard text

Post by Graham » 02 Dec 2017 15:38

I routinely use AUTOMAGIC to take text copied from books I am reading, append it to a file, and store that file in my tablet, and in Dropbox. That is easy. But I often read 2 or 3 books simultaneously, and currently all my clippings from all 3 books are appended to the same file and I am obliged to sort them out later with a word processor.
Is there a way that the flow can :-
1- know from which document the clipboard text was copied
2- make a file with that name, if it does not already exist
3- append the text clipping to the correct file.
That would save so much time!

I guess it is item 1 that baffles me most. Can it be done?
Thanks for any help.
Graham

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Know Source of clipboard text

Post by Desmanto » 02 Dec 2017 18:11

1. Currently, there is no way to do that, clipboard is handled by OS. But maybe it is possible for Martin to add the source app in Trigger Clipboard Changed.
2. Write to file action, with append checked will automatically create the file first if it is not exist yet.\
3. The full implementation will require 4 flows. But can be reduced to 2 only if you already know how to combine triggers to single flow and split them using multiple parallel expression viewtopic.php?f=5&t=7103

What app do you use to read the book? What file? PDF? ePub? I will make assumption you are using adobe reader for android, and open pdf files.

The first 2 flows will be using triggers app task started and ended, adobe reader. In both flows, enable/disable the flow 3 and flow 4 accordingly.
So when adobe reader is opened, enable flow 3 and flow 4. Adobe reader is closed, disable them.

Flow 3 will be using trigger UI event (you need to enable accessibility services for Automagic), component clicked, package name com.adobe.reader; matches regex : .*\.pdf
The action after it only single script with 2 lines

Code: Select all

book = findAll(text, "(.*)\\.pdf", true);
global_book_name = book[0][1];
What happened is, when you click to open the pdf in adobe reader, it will trigger this flow 3. Script will parse the pdf name, for example regexbuddy.pdf. Using regex parsing, we will take out the file name, removing the .pdf. Then save this to a global variable for later use. So now we have the file name as the source of the book name.

Flow 4 will be using Trigger Clipboard changed. After clipboard changes, put conditon App Process Running, adobe reader. This will ensure the flow will only continue if the clipboard changed trigger inside adobe reader. Use action write to file as you have done, append it to the file name from glovar. Probably something like
File : /storage/emulated/0/Automagic/{global_book_name}.txt
Text : {clip_data}

The book name will stay for a long time, until you back from the pdf, click another pdf. Then the global_book_name will be set to the new name. Anything you copy from that book, will be append to new text file (if not exist yet).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Graham
Posts: 7
Joined: 28 Dec 2013 16:19

Re: Know Source of clipboard text

Post by Graham » 03 Dec 2017 14:09

Many thanks for taking so much trouble, and for such a full response! I should be able to implement what you suggest, though I am a beginner!

In fact I am usually reading ePUB files in Moon+ Reader Pro, or PDF files in XODO.

As a stop-gap solution (until I try your more subtle approach), yesterday I made a flow where after copying the clipboard content, there is an Input Dialog where the "Default Value" is blank. Then if I fail to enter anything into the dialog, a condition using the expression isEmpty({value}) diverts the flow and appends the clip to a file I call Assorted.txt. Alternatively, if I enter the first syllable of the book or author name (so that {value} is not empty), a file using {value} as filename is generated and the clip appended to it. Then the files are copied to memory and to Dropbox. This works well, but of course I have to interact with the Input Dialog. On the other hand it is easy, reliable, and also puts clips from websites, news sites etc into my Assorted.txt file .
I will try to implement your suggestion. It would be great to eliminate the Input Dialog!

Many thanks
Graham

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Know Source of clipboard text

Post by Desmanto » 04 Dec 2017 04:14

Any reader is ok. Just make sure you open the file from the list. SO UI event can detect the component click. File format also can be changed, just replace the extension in regex.

The same flow can be expanded to cover other apps too. Just check for which app is running. If it is browser, copy the text directly to file, without using the global_book_name.

Alternatively, you can use the input dialog - single choice menu. Put the frequent use name in a global_book_list. Later show this as the choice, plus the end add option to add new. Add new will prompt another input dialog to add new book list, and loop back to the same single choice menu. This way, you don't have to retype the frequent use ones.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply