Created
December 23, 2011 14:04
Revisions
-
upsuper revised this gist
Jan 17, 2012 . 1 changed file with 24 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ # - * - coding: UTF-8 - * - import subprocess def macosx_set_clipboard(text): @@ -15,17 +13,32 @@ def macosx_send_keys(text): code = code % (text, ) p.communicate(code) def xte_send_keys(text): subprocess.call(['xte', 'str ' + text]) def unsupported_platform(*args, **kws): raise 'Unsupported platform' set_clipboard = unsupported_platform send_keys = unsupported_platform import platform _system = platform.system() if _system == 'Darwin': set_clipboard = macosx_set_clipboard send_keys = macosx_send_keys # pre send to accelerate sendkeys _p = subprocess.Popen('osascript', stdin=subprocess.PIPE) _p.stdin.write('tell application "System Events" to keystroke ""') _p.stdin.close() elif _system == 'Linux': def prog_exists(prog): import os import os.path as path for p in os.environ["PATH"].split(os.pathsep): exe_file = path.join(p, prog) if path.exists(exe_file): return True return False if prog_exists('xte'): send_keys = xte_send_keys -
upsuper revised this gist
Jan 1, 2012 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,11 @@ def unsupported_platform(*args, **kws): raise 'Unsupported platform' if platform.system() == 'Darwin': # pre send to accelerate sendkeys p = subprocess.Popen('osascript', stdin=subprocess.PIPE) p.stdin.write('tell application "System Events" to keystroke ""') p.stdin.close() # set methods set_clipboard = macosx_set_clipboard send_keys = macosx_send_keys else: -
upsuper created this gist
Dec 23, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ # - * - coding: UTF-8 - * - import sys import platform import subprocess def macosx_set_clipboard(text): p = subprocess.Popen('pbcopy', stdin=subprocess.PIPE) p.communicate(text) def macosx_send_keys(text): text = text.replace('\\', '\\\\').replace('"', '\\"') code = 'tell application "System Events" to keystroke "%s"' p = subprocess.Popen('osascript', stdin=subprocess.PIPE) code = code % (text, ) p.communicate(code) def unsupported_platform(*args, **kws): raise 'Unsupported platform' if platform.system() == 'Darwin': set_clipboard = macosx_set_clipboard send_keys = macosx_send_keys else: set_clipboard = unsupported_platform send_keys = unsupported_platform