Monday, April 4, 2011

Quick script to copy text to Android mobile

Hi All,

I wrote a small script to quickly copy some text from linux computer to an android mobile.
To use it,
  • Install Barcode Scanner in your android mobile from here (This is a must app for any android mobile)
  • Copy the below code to a file named and give it executable permissions,
  • Create a Custom application launcher in the top panel to launch the saved script.
Now when you want to copy some text,
  • Using mouse, select the text or url you want to copy.
  • Click on the launcher you created.
  • Scan the barcode displayed on the screen using your android mobile. :-)


#Following function is copied from
#@ uri_escape - convert STRING to hex-encoded string
#@ and assign to optional VAR or _URI_ESCAPE
#@ Author: Chris F.A. Johnson, 2009-03-25
uri_escape ()
local string x;
while [ -n "$string" ]; do
case $string in
printf -v x "%s%c" "$x" "$string"
printf -v x "%s%%%X" "$x" "'$string"
eval "$var=\$x"

data=`xclip -o`
uri_escape "$data" data

#Replace eog with your image viewer application if you are not using gnome desktop.
eog "$uri" &> /dev/null &