After I started using this, I found that I sometimes want to capture multi-line selections from non-Leo sources, like a browser for example. So I added a modified version of the script that logs the clipboard text to the log file. I added an item for this script to my custom "Local" menu. A slight complication is how to indent a multi-line selection so that it's easy to read. This script uses one approach: so far, so good. Here's the script:
"""Write clipboard text to a log file.""" from pathlib import Path import time from textwrap import fill LOG = c.config.getString('notelog') or '~/.leo/temp/notelog.txt' ACTUALPATH = Path(LOG).expanduser() text = g.app.gui.getTextFromClipboard() if text.strip(): if len(text) > 65: text = '\n' + fill(text, 70, initial_indent = ' ' * 4, subsequent_indent = ' ' * 4) now = time.time() localtime = time.strftime("%Y-%m-%d %H:%M", time.localtime(now)) with open(ACTUALPATH, 'a', encoding = 'utf-8') as f: f.write(f'{localtime}\t{text}\n') g.es(f'Wrote note to {ACTUALPATH}') This script also lets you optionally set the location of the log file with the @string setting notelog. On Wednesday, May 17, 2023 at 10:35:54 AM UTC-4 Thomas Passin wrote: > Trying it out got me to thinking that it would be handy to be able to log > quick little notes. The following script writes the cursor line on the > body to a note log file, whose path can optionally be specified in a > setting. The idea is that you could write a brief one-line note and pop it > right into the log file with a time stamp - > > """Write cursor line to a log file.""" > from pathlib import Path > import time > > LOG = c.config.getString('notelog') or '~/.leo/temp/notelog.txt' > ACTUALPATH = Path(LOG).expanduser() > > w = c.frame.body.wrapper > j = w.getInsertPoint() > s = c.p.b > beg, end = g.getLine(s, j) > line = s[beg:end] > > if line: > now = time.time() > localtime = time.strftime("%Y-%m-%d %H:%M", time.localtime(now)) > with open(ACTUALPATH, 'a', encoding = 'utf-8') as f: > f.write(f'{localtime}\t{line}\n') > > You could do the same thing by keeping a text editor window with the log > file open all the time, but if you are working with Leo anyway this would > be more convenient. > On Wednesday, May 17, 2023 at 5:26:25 AM UTC-4 Edward K. Ream wrote: > >> On Tuesday, May 16, 2023 at 5:31:04 PM UTC-5 tbp1...@gmail.com wrote: >> >> The script registers as an idle time handler. If a minute has elapsed >> since the last check, the script looks to see if the currently focused >> outline and node have changed since the last check. If so, it writes the >> time and the node's UNL to the log file. >> >> >> Clever idea. I use the github issue tracker for almost everything I do. >> That's usually a good enough reminder :-) >> >> Edward >> > -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/b783c12d-78ed-4387-9b3c-6154b9f9111en%40googlegroups.com.