Difference between revisions of "Changing Clipboard Data From The Shell"

From WebOS Internals
Jump to navigation Jump to search
(Added WebOS Clipboard Buddy)
Line 4: Line 4:
  
  
== Steps ==
+
== Manual Steps ==
  
  
'''Step One:''' Root your Pre.
+
'''Step One:''' Access the Linux portion of your Pre
  
 
'''Step Two:''' Edit your clipboard file '''(you need to at least copy and paste something once for the file to show up)'''
 
'''Step Two:''' Edit your clipboard file '''(you need to at least copy and paste something once for the file to show up)'''
Line 19: Line 19:
 
'''Tip:''' for more info on how to use vi, remember Google is your friend...
 
'''Tip:''' for more info on how to use vi, remember Google is your friend...
  
 +
By: JRG
 +
 +
 +
== WebOS Clipboard Buddy ==
 +
 +
'''WebOS Clipboard Buddy''' is a very simple pyGTK app that allows you to easily copy data between your desktop's clipboard and the Pre's clipboard. Feel free to improve upon it. Currently this is Linux only, though it should be trivial to get working under windows. It currently requires that you have the SDK installed (specifically that novacom is functional and available at /usr/local/bin/novacom/novacom).
 +
 +
<pre>
 +
#!/usr/bin/env python
 +
 +
# Copyright (c) 2009 James Hines
 +
 +
# Permission is hereby granted, free of charge, to any person
 +
# obtaining a copy of this software and associated documentation
 +
# files (the "Software"), to deal in the Software without
 +
# restriction, including without limitation the rights to use,
 +
# copy, modify, merge, publish, distribute, sublicense, and/or sell
 +
# copies of the Software, and to permit persons to whom the
 +
# Software is furnished to do so, subject to the following
 +
# conditions:
 +
 +
# The above copyright notice and this permission notice shall be
 +
# included in all copies or substantial portions of the Software.
 +
 +
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 +
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 +
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 +
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 +
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 +
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 +
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 +
# OTHER DEALINGS IN THE SOFTWARE.
 +
 +
 +
import gtk
 +
import pygtk
 +
import commands
 +
from subprocess import *
 +
 +
def quit_cb(widget, data = None):
 +
    if data:
 +
        data.set_visible(False)
 +
        gtk.main_quit()
 +
       
 +
def popup_menu_cb(widget, button, time, data = None):
 +
    if button == 3:
 +
        if data:
 +
            data.show_all()
 +
            data.popup(None, None, None, 3, time)
 +
            pass
 +
 +
def pre_to_clipboard_cb(widget):
 +
    clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
 +
    result = commands.getstatusoutput('/bin/echo "cat /tmp/webkit-clipboard; exit" | /usr/local/bin/novacom/novacom open tty://0')
 +
    text = result[1].split("\n", 1)[1].rstrip("\r\n")
 +
    print text
 +
    clipboard.set_text(text)
  
 +
def clipboard_to_pre_cb(widget):
 +
    clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
 +
    clipboard.request_text(push_to_pre)
  
 +
def push_to_pre(clipboard, text, data):
 +
    pre = Popen(["/usr/local/bin/novacom/novacom", "-t", "open", "tty://0"], stdin=PIPE, stdout=PIPE)
 +
    eof_marker = "CLIPBOARDEOFMARKER"
 +
    pre_output = pre.communicate("cat <<" + eof_marker + "> /tmp/webkit-clipboard\n" + text + "\n" + eof_marker + "\nexit\n")
 +
    print pre_output
 +
   
  
 +
def clipboard_cb(clipboard, text, data):
 +
    print text
  
By: JRG
+
def about_icon_cb(widget, data = None):
 +
    msgBox = gtk.MessageDialog(parent = None, buttons = gtk.BUTTONS_OK, message_format = "WebOS Clipboard Agent\nVersion 1.0.0\nCopyright 2009, James Hines.")
 +
    msgBox.run()
 +
    msgBox.destroy()
 +
   
 +
statusIcon = gtk.StatusIcon()
 +
   
 +
menu = gtk.Menu()
 +
menuItem = gtk.MenuItem(label = "Copy from Pre")
 +
menuItem.connect('activate', pre_to_clipboard_cb)
 +
menu.append(menuItem)
 +
menuItem = gtk.MenuItem(label = "Copy to Pre")
 +
menuItem.connect('activate', clipboard_to_pre_cb)
 +
menu.append(menuItem)
 +
menuItem = gtk.SeparatorMenuItem()
 +
menu.append(menuItem)
 +
menuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
 +
menuItem.connect('activate', about_icon_cb)
 +
menu.append(menuItem)
 +
menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
 +
menuItem.connect('activate', quit_cb, statusIcon)
 +
menu.append(menuItem)
 +
   
 +
statusIcon.set_from_stock(gtk.STOCK_PASTE)
 +
statusIcon.set_tooltip("WebOS Clipboard Agent")
 +
statusIcon.connect('popup-menu', popup_menu_cb, menu)
 +
statusIcon.set_visible(True)
 +
   
 +
gtk.main()
 +
</pre>

Revision as of 19:17, 3 September 2009

Changing Clipboard Data From The Shell

When you use the copy and paste function on your Pre the string has to go somewhere. Right? Well, from what I learned from tharris which was that the string goes to a file called webkit-clipboard which is located in the /tmp directory.


Manual Steps

Step One: Access the Linux portion of your Pre

Step Two: Edit your clipboard file (you need to at least copy and paste something once for the file to show up)

vi /tmp/webkit-clipboard

Step Three: Save it.

Tip: for more info on how to use vi, remember Google is your friend...

By: JRG


WebOS Clipboard Buddy

WebOS Clipboard Buddy is a very simple pyGTK app that allows you to easily copy data between your desktop's clipboard and the Pre's clipboard. Feel free to improve upon it. Currently this is Linux only, though it should be trivial to get working under windows. It currently requires that you have the SDK installed (specifically that novacom is functional and available at /usr/local/bin/novacom/novacom).

#!/usr/bin/env python

# Copyright (c) 2009 James Hines

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.


import gtk
import pygtk
import commands
from subprocess import *

def quit_cb(widget, data = None):
    if data:
        data.set_visible(False)
        gtk.main_quit()
        
def popup_menu_cb(widget, button, time, data = None):
    if button == 3:
        if data:
            data.show_all()
            data.popup(None, None, None, 3, time)
            pass

def pre_to_clipboard_cb(widget):
    clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
    result = commands.getstatusoutput('/bin/echo "cat /tmp/webkit-clipboard; exit" | /usr/local/bin/novacom/novacom open tty://0')
    text = result[1].split("\n", 1)[1].rstrip("\r\n")
    print text
    clipboard.set_text(text)

def clipboard_to_pre_cb(widget):
    clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
    clipboard.request_text(push_to_pre)

def push_to_pre(clipboard, text, data):
    pre = Popen(["/usr/local/bin/novacom/novacom", "-t", "open", "tty://0"], stdin=PIPE, stdout=PIPE)
    eof_marker = "CLIPBOARDEOFMARKER"
    pre_output = pre.communicate("cat <<" + eof_marker + "> /tmp/webkit-clipboard\n" + text + "\n" + eof_marker + "\nexit\n")
    print pre_output
    

def clipboard_cb(clipboard, text, data):
    print text

def about_icon_cb(widget, data = None):
    msgBox = gtk.MessageDialog(parent = None, buttons = gtk.BUTTONS_OK, message_format = "WebOS Clipboard Agent\nVersion 1.0.0\nCopyright 2009, James Hines.")
    msgBox.run()
    msgBox.destroy()
    
statusIcon = gtk.StatusIcon()
    
menu = gtk.Menu()
menuItem = gtk.MenuItem(label = "Copy from Pre")
menuItem.connect('activate', pre_to_clipboard_cb)
menu.append(menuItem)
menuItem = gtk.MenuItem(label = "Copy to Pre")
menuItem.connect('activate', clipboard_to_pre_cb)
menu.append(menuItem)
menuItem = gtk.SeparatorMenuItem()
menu.append(menuItem)
menuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
menuItem.connect('activate', about_icon_cb)
menu.append(menuItem)
menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
menuItem.connect('activate', quit_cb, statusIcon)
menu.append(menuItem)
    
statusIcon.set_from_stock(gtk.STOCK_PASTE)
statusIcon.set_tooltip("WebOS Clipboard Agent")
statusIcon.connect('popup-menu', popup_menu_cb, menu)
statusIcon.set_visible(True)
    
gtk.main()