Skip to content

Instantly share code, notes, and snippets.

@yingted
Created September 14, 2013 05:43
Show Gist options
  • Save yingted/6559102 to your computer and use it in GitHub Desktop.
Save yingted/6559102 to your computer and use it in GitHub Desktop.
Copy the local clipboard to Android clipboard over ssh or adb. Set login to -d or -e to force adb to only look for devices or emulators. See also copy-clipboard-from-android.sh.
#!/bin/sh
# Copies local X11 secondary buffer to the Android clipboard.
# Useful for debugging.
delay=3000
login=my-android-ssh-name # ssh $login or adb $login shell should log you in
while getopts 't:q' opt
do
case $opt in
h)
login="$optARG";;
t)
delay="$optARG";;
q)
quiet=1;;
esac
done
[ $# -ge 1 ] && login="$1" && shift;
#end constants
paste(){
xargs -0e$'\0' ssh "$login" 'service call clipboard 2 i32 1 i32 1 s16' &>/dev/null # uncomment to use ssh
#xargs -0e$'\0' adb $login shell 'service call clipboard 2 i32 1 i32 1 s16' &>/dev/null # uncomment to use adb
ret=$?
}
[ -z "$DISPLAY" ] && paste || xsel -bo | paste
msg(){
[ -z "$DISPLAY" ] && tput bold && echo -n "$1" && tput sgr0 && echo : && echo "$2" || notify-send -t "$delay" "$1" "$2"
}
case $ret in
255)
msg "SSH error" "Error connecting";;
0)
msg "pasted to" "$login";;
*)
msg "Remote error" "Error code $ret";;
esac
exit $ret
@TheHippo
Copy link

TheHippo commented Dec 9, 2013

This does not work on devices with ICS or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment