Created
January 25, 2014 16:24
-
-
Save soyo42/150d5c55beec419dc9b2 to your computer and use it in GitHub Desktop.
chose string from menu, write it into tab on the left side (xterm), hit enter
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/python | |
import sys | |
import exceptions | |
import time | |
from autopy import key | |
if len(sys.argv) != 2: | |
sys.stderr.write('usage:: {} <file containing commands>\n'.format(sys.argv[0])) | |
sys.exit(1) | |
def enterCommandInLeftTab(cmd): | |
key.tap(key.K_PAGEUP, key.MOD_CONTROL) | |
first = True | |
for cmdChip in cmd.split(':'): | |
if first: | |
first = False | |
else: | |
key.tap(':', key.MOD_SHIFT) | |
key.type_string(cmdChip) | |
key.tap(key.K_RETURN) | |
#time.sleep(1) | |
#key.tap(key.K_PAGEDOWN, key.MOD_CONTROL) | |
def dumpMenu(list, question): | |
idx = 1 | |
answers = [] | |
for entry in list: | |
if entry == '': | |
continue | |
print('\033[32;1m{:2d}\033[0m ) {}'.format(idx, entry)) | |
answers.append(entry) | |
idx += 1 | |
answerIdx = None | |
ansLimit = len(answers) | |
while answerIdx == None: | |
try: | |
answer = raw_input(question) | |
if answer == '': | |
continue | |
print('ans: '+answer) | |
answerIdx = int(answer) - 1 | |
if answerIdx < 0 or answerIdx >= ansLimit: | |
answerIdx = None | |
print('out of range .. {}'.format(answerIdx)) | |
except (exceptions.SyntaxError, exceptions.ValueError) as e: | |
#print(e.__class__, e) | |
answerIdx = None | |
print('wtf? .. {}'.format(e)) | |
return [answerIdx, answers[answerIdx]] | |
cmds = ['EXIT'] | |
with open(sys.argv[1], 'r') as commands: | |
for line in commands: | |
line = line.strip() | |
if len(line) > 0 and line[0] == '#': | |
continue | |
cmds.append(line) | |
ans = None | |
while True: | |
ans = dumpMenu(cmds, "Enter choice.. ") | |
if ans[0] == 0: | |
break | |
print('answer: {}'.format(ans[1])) | |
enterCommandInLeftTab(ans[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment