def wrap_tag(tag): clipboard_empty = False try: clip = get_clip() except: clip = "" clipboard_empty = True clip = "<{0}>{1}</{0}>".format(tag, clip) try: set_clip(clip) except Exception as e: notify_error(e)
# Same basic thing as "Wrap in blockquote tags" except it ignores # any selected text (and is maybe a bit simpler) from scriptlib import get_clip, set_clip, notify_error clipboard_empty = False try: clip = get_clip() except: clip = "" clipboard_empty = True clip = "<blockquote>" + clip + "</blockquote>" try: set_clip(clip) except Exception as e: notify_error(e) time.sleep(0.01) # Firefox doesn't understand Shift+Ctrl+V as another paste keyboard.send_keys("<ctrl>+v")
# Wrap the selection text in a PHP 'print_r' statement for debugging If # selection is empty, just put the cursor inside the 'print_r()' import time from scriptlib import get_sel, get_clip, set_clip # get existing clipboard text, so we can restore it try: clip_text = get_clip() except: clip_text = '' try: sel = get_sel() except: sel = '' set_clip(sel) engine.run_script('PHP echo raw (from clipboard)') if clip_text: time.sleep(0.1) set_clip(clip_text)
import time from scriptlib import wrap_clip, get_clip, set_clip # save the clipboard so we can restore it try: oldclip = get_clip() except: # catches errors or an empty clipboard oldclip = '' # wrap_clip returns the # of times to press <left> to get cursor in # the position specified in the format string ('%|') lefts = wrap_clip('[[wp:%c%||%c]]') keyboard.send_keys("<ctrl>+v") # give it a tick to finish pasting that... time.sleep(0.1) keyboard.send_keys('<left>' * lefts) if oldclip: time.sleep(0.1) set_clip(oldclip) # restore previous clipboard contents
from scriptlib import get_sel, get_clip, set_clip, for_length_of no_selection = False try: sel = get_sel() except: sel = "" no_selection = True try: clip_text = get_clip() # because we're about to clobber it except: clip_text = "" sel = "<tt>" + sel + "</tt>" try: set_clip(sel) except Exception as e: notify_error(e) time.sleep(0.01) keyboard.send_keys("<shift>+<ctrl>+v") # paste over the selection # Put the cursor inside the <tt></tt> tags if the selection was empty if no_selection: time.sleep(0.01) keyboard.send_keys(for_length_of("</tt>", "<left>")) if clip_text: time.sleep(0.1) set_clip(clip_text) # restore previous contents
no_selection = False try: sel = get_sel() except: sel = "" no_selection = True try: clipb = get_clip() # because we're about to clobber it except: clipb = "" sel = "<blockquote>" + sel + "</blockquote>" try: set_clip(sel) except Exception as e: notify_error(e) time.sleep(0.01) # Firefox doesn't understand Shift+Ctrl+V as another paste keyboard.send_keys("<ctrl>+v") # paste over the selection # Put the cursor inside the <blockquote></blockquote> tags if the # selection was empty if no_selection: time.sleep(0.01) keyboard.send_keys(for_length_of("</blockquote>", "<left>")) if clipb:
# save the clipboard so we can restore it try: clip_text = get_clip() except: # catches errors or an empty clipboard clip_text = '' if re.match('[a-zA-Z]+://', clip_text): url = clip_text else: notify_warn('No URL found on clipboard') url = '' try: selection = get_sel() except: selection = '' # wrap_clip returns the # of times to press <left> to get cursor in # the position specified in the format string ('%|') lefts = wrap_clip('[%c ' + selection + ']', clip_text=url) keyboard.send_keys("<ctrl>+v") # give it a tick to finish pasting that... time.sleep(0.1) keyboard.send_keys('<left>' * lefts) if clip_text: time.sleep(0.1) set_clip(clip_text) # restore previous clipboard contents
# Wrap the clipboard text in a print_r for PHP debugging import time from scriptlib import get_clip, set_clip, wrap_clip DELAY = 0.08 START = 'echo "<pre>"; print_r(' END = '); echo "</pre>\\n";' # get clipboard contents so we can restore later try: clip_text = get_clip() except: clip_text = '' lefts = wrap_clip(START + '%c' + END, clip_text=clip_text) keyboard.send_keys('<shift>+<ctrl>+v') time.sleep(DELAY) keyboard.send_keys('<left>' * lefts) if clip_text: time.sleep(DELAY) set_clip(clip_text)