在X11中,您必须与选择所有者通信,询问支持的格式,然后以特定格式请求数据。我认为最简单的方法是使用现有的窗口工具包。例如。与Python和GTK:
#!/usr/bin/python
import glib,gtk
def test_clipboard():
clipboard = gtk.Clipboard()
targets = clipboard.wait_for_targets()
print "Targets available:",",".join(map(str,targets))
for target in targets:
print "Trying '%s'..." % str(target)
contents = clipboard.wait_for_contents(target)
if contents:
print contents.data
def main():
mainloop = glib.MainLoop()
def cb():
test_clipboard()
mainloop.quit()
glib.idle_add(cb)
mainloop.run()
if __name__ == "__main__":
main()
输出将如下所示:
$ ./clipboard.py
Targets available: TIMESTAMP,TARGETS,MULTIPLE,text/html,text/_moz_htmlcontext,text/_moz_htmlinfo,UTF8_STRING,COMPOUND_TEXT,TEXT,STRING,text/x-moz-url-priv
...
Trying 'text/html'...
I asked the same question on superuser.com,because I was hoping there was a utility to do this,but I didn't get any informative responses.
Trying 'text/_moz_htmlcontext'...
...
Trying 'STRING'...
I asked the same question on superuser.com,but I didn't get any informative responses.
Trying 'text/x-moz-url-priv'...
http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard