Create a text memo from the selected text

Create a text memo from the selected text

Often, while surfing on the Internet there is a need to store some information on your computer. A small script which will save the information to a text file. It is very convenient.

You can save the entire page, but it is not always necessary, often you want to save a few lines of text.

Previously, manually created text file and copied it right, but it is exhausting.

Then it was decided to automate this process was written a small script to create notes that I would like to share with you.

The principle of operation of a script.
Let’s say I want to save the information to disk. Select the text, run the script (I run on a combination of hotkeys). The selected text itself is copied into the opened window:

Create a text memo from the selected textCreate a text memo from the selected text

It can be edited as desired. Press OK.

A window opens to enter the name of the file that will be saved note:

Create a text memo from the selected text

If you leave this field blank, the title will be “Note [random number].txt”.
Press OK. All selected text will be saved into the text file.

Let’s check:

Create a text memo from the selected text

Create a text memo from the selected textCreate a text memo from the selected text

Guide – “How to do?”.
Must be installed packages zenityxclip:

sudo apt-get install -y zenity xclip[/simterm]

Create the script file:

nano notes[/simterm]

You can create a file in a text editor, where you want. Paste into this file this code:

#!/bin/bash
# Adds the selected text to the note at the specified location
# Must be installed: zenity, xclip
# $ sudo apt-get install zenity xclip
out=”/tmp/notes.$$”
dir=”$HOME/Downloads” # folder where will be stored the notes
xclip -o | zenity –width=600 –height=300 –title “Text of the note” –text-info –editable > “$out”
if [ $? -eq 0 -a “`cat “$out”`” != “” ]; then
name=$(zenity –title “Title of the note” –entry –text “Enter the title”)
if [ $? -eq 0 ]; then
if [ “`echo $name`” = “” ]
then name=”Note $$”
fi
cp “$out” “$dir/$name.txt”
fi
fi
rm “$out”
exit 0[/simterm]

Folder where will be saved the notes is specified in the variable dir. You can change on your own.
Save and close the editor.
Make the script executable:

chmod +x notes[/simterm]

Check the correct work of the script

./notes[/simterm]

Add in your system hot key to run a script or hot corner of the screen.
There is a small “glitch” – if you select text and then click elsewhere, for example, to open any menu, the text is not automatically inserted, a window opens empty.
It is therefore desirable to run a script with hotkeys.
I hope someone will find it interesting.

Good Luck!!!

Source

Share to friends
Shekin
Rate author
( No ratings yet )
MintGuide.Org
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Gall Anonimus
Gall Anonimus
2022 years ago

This is great idea. I dont have to install too much applications.
Very usefull script. Thanks for your invention.