Created
May 31, 2015 15:48
-
-
Save leftaroundabout/eb228668391412c35135 to your computer and use it in GitHub Desktop.
Edit a gtk-clipboard “in-place”.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import gtk | |
import chardet | |
import os | |
import getopt | |
import subprocess | |
dtype = 'text/html' | |
htmlclip = gtk.Clipboard().wait_for_contents(dtype).data | |
encoding = chardet.detect(htmlclip)['encoding'] | |
# Shove the clipboard to a temporary file | |
tmpfn = '/tmp/htmlclip_%i' % os.getpid() | |
with open (tmpfn, 'w') as editfile: | |
editfile.write(htmlclip.decode(encoding)) | |
# Manually edit the temporary file | |
subprocess.call(['vi', tmpfn]) | |
with open (tmpfn, 'r') as editfile: | |
htmlclip = editfile.read().encode(encoding) | |
# Put the modified data back to clipboard | |
gtk.Clipboard().set_with_data( | |
[(dtype,0,0)], | |
lambda cb, sd, info, data: sd.set(dtype, 8, htmlclip), | |
lambda cb, d: None ) | |
gtk.Clipboard().set_can_store([(dtype,0,0)]) | |
gtk.Clipboard().store() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is intended a useful hack to make up for Thunderbird's lack of a proper html source editor. Just select all, copy, execute this script (which invokes
vi
or whatever editor you specify), manipulate, close and paste back into the Thunderbird composition window.