Sometimes, I need copy some links or text from computer to my smart phone. It’s such a bad experience to type all of the contents by myself. So I made a tool in Linux called “Jtext2code”, which can generate a QR code according to the text you choose. Use your smart phone application like Scanner to scan the picture generated, you can get the information you choose easily.
Let’s build this.
Install python, python-pip:
sudo apt-get install python python-pip
Install qrcode, a python lib can generate QR code:
sudo pip install qrcode
Install feh, a command line tool to view pictures:
sudo apt-get install feh
Jtext2code was made up with three parts.
- Get the clipboard information.
- Generate the QR code.
- Display the QR code picture.
I’ll explain the three one by one.
1.Use python to get the text we choose. 
#!/usr/bin/python2.7 import pygtk import gtk # get the clipboard clipboard = gtk.clipboard_get() # read the clipboard text data. you can also read image and # rich text clipboard data with the # wait_for_image and wait_for_rich_text methods. text=clipboard.wait_for_text()
2.Generate the QR code picture.
import qrcode # Save text information to QR.png qrcode_image=qrcode.make(text) qrcode_image.save('QR.png')
3.Display the picture we just created.
import os # Call feh in python to display picture s=os.popen('feh QR.png')
Save all the three parts to one file name “Jtext2code.py”
Make it executable:
chmod +x Jtext2code.py
Link to /bin/
sudo ln -s `pwd`/Jtext2code.py /bin/Jtext2code
When you use the tool you should first copy the text you want to transfer, then go to the terminal then run
and you can get the QR code picture. Finally, use your smart phone to scan the picture.
Tip: You can create a launcher in the LinuxMint(XFCE) for better using experience: Right click in the desktop to Create launcher
Besides, you can also drag the launcher to the panel.
So that it will be more convenient to open a terminal to run the program.
Remember: Copy text, then run Jtext2code
I want to know:
- How can I get the PRIMARY selection in python, not CLIPBOARD selection? (If I can get PRIMARY selection, I don’t have to copy the text to the clipboard, just select the text,and run Jtext2code. More convenient, right? )
——————-Oct 29th 2016———————————
One possible answer: Use python to call Linux commands.
import commands text=commands.getoutput("xsel -o")
Use the “xsel -o” to get the PRIMARY selection.
- How can I add a new item like “Jtext2code” to the right click menu ?
(If I can do this, I can just select the text and right click, then –>Jtext2code. It’s pretty cool.)
————–Oct 29th 2016———————————
Although I don’t get the answer, but this is a solution to make it more convenient–Add a shortcut for this application:
Edit xfce4-keyboard-shortcuts.xml (for I can’t add shortcuts in MintXfce settings.)
add the following line to this file
<property name="&lt;Alt&gt;&lt;Control&gt;S" type="string" value="Jtext2code"/>
Save this file, and login out and in. Type Ctrl+Alt+S will trigger Jtext2code
Thank you very much.