[Nexus One Themes and Apps] fubaya:
Sharing clipboard both directions with a PC via ssh (sorry, Linux only)

This is sort of like Chrome to Phone except it aims to be better and share the entire clipboard between the phone and linux box, going either direction. This is set up to run from the phone, so you can't push text from the computer to the phone 100 miles away, but you can use the phone to push to and pull from the computer from anywhere.

Unfortunately, it's not entirely complete. Tasker can't currently read whole files without losing blank lines so I just set up the "computer clipboard to phone clipboard" part to only read one line as I assume sharing links is probably people's main use for this. Once Tasker gets a "read file" action, and Pent said it was on his todo, just change one step in Tasker to grab the whole file instead of one line.

I found it useful yesterday when taking my daughter to a birthday party. We were running late and I was on the phone and needed directions. I opened an email on the computer, highlighted the text (windoze users: that copies it on linux :p), then left the house. While driving down the road 10 minutes later, I finally ended my call then clicked the Tasker widget to copy the text from the computer to the phone. Then I opened maps and pasted it in the search box and navigated to the party.

Things you need:

1- ssh set up to log in to the Linux box using keys. For these examples, you don't need to log into the phone with ssh, everything is ran from the phone. You'll need to test your ssh commands first and these examples use ssh USER@IP -i KEYFILE as general ssh commands that you'll need to plug and chug. You may be able to plug in your user, ip and key, or you may need something a little different, that's up to you. If your ssh gets this error: stderr: ssh: Warning: failed creating //.ssh:

Read-only file system

stderr: Host is not in the trusted hosts file try this.

2- xsel and/or xclip on the Linux box. These are two command line copy and paste utilities and they're pretty old and probably not maintained anymore so you might have to try both to see which works best. On my computer (Slack13), only one works to paste and the other works for copying, so I have to use both.

3- you probably need a terminal on the phone to test this stuff

4- maybe a little command line knowledge in case this needs tweaked for your system, but if you can set up ssh keys you can do this.

All command line examples in this post are short shell scripts placed in my path on the computer or phone. You could set up aliases or run the commands however you want (a couple may work if ran directly in Tasker with the Locale Execute plugin), but I'm using scripts. If you understood what I just said, you should be able to do it your own way.

On the Linux side

We need to set up a way to get text in and put it in the clipboard and a way to get it from the clipboard. This can be done with one xsel or xclip command, but since both use the X server, we have to set the display before running them while logged in through ssh, then unset it for a clean exit.

Here are the two scripts you'll need in Linux. I'll name them linuxclip and linuxcopy because we'll need those names later. Again, xsel and xclip may be interchangeable for you so use whichever one works best.

linuxclip

#! /bin/sh
# displays the contents of the Linux clipboard
export DISPLAY=:0.0
xsel -p
unset DISPLAY

linuxcopy

#! /bin/sh
# takes text in and puts it in Linux clipboard
in=$(cat /dev/stdin) # try "in=$(cat -)" if that doesn't work
export DISPLAY=:0.0
echo "$in" | xclip
unset DISPLAY

That's all we need on the computer.

On the Phone

Now we need a couple ssh commands on the phone. Again, these can probably be executed in various ways, even in Tasker itself, but I'm using scripts.

To paste from the computer to the phone (this currently only does one line due to Tasker's problem reading entire files. Like I said, it's on Pent's todo list so once a "read file" is available, just change step 5)

fromlinuxclip script on the phone

#! /system/bin/sh

ssh USER@IP -i KEYFILE 'linuxclip' > /sdcard/.clipboard || echo "failed" > /sdcard/.clipboard

Tasker

1- Delete File .clipboard

2- using the Locale Execute Plugin, execute: @! fromlinuxclip

3- Variable clear > %TEXT

4- Variable set > %ONE to 1

5- Read line > file: .clipboard, Line: %ONE, To Var: %TEXT (change this action to "Read File" when available in Tasker)

6- Go To 5 > if %TEXT matches EOF."

7- Set Clipboard %TEXT

Step 2 uses "@!". "@" keeps it from flashing a message telling you it ran and "!" is for root. I didn't test it without root.

Step 6 is necessary because the task runs faster than step 2 can execute, thus giving you EOF every time. The fromlinuxclip script puts "failed" in the file if the ssh connection doesn't work, thus populating the file and giving it something to copy to avoid an infinite loop.

Some optional actions you may want to use:

Warn you if unable to connect to computer:

Flash > ssh connection failed, nothing copied! > if %TEXT matches failed

Display what you just copied to the phone:

Flash > Copied: %TEXT if %TEXT doesn't match http*

If you just copied a URL, open the browser to that URL:

Browse URL > URL: %TEXT if %TEXT matches http*

To paste from the phone to the computer

2linuxclip script on the phone

#! /system/bin/sh

cat /sdcard/.clipboard | ssh USER@IP -i /PATH/TO/SSHKEY 'linuxcopy'

Tasker

1- Write File > .clipboard text > %CLIP

2- using the Locale Execute Plugin execute @! 2linuxclip

That's it!

Hope this is useful for someone.