Created
April 9, 2017 00:09
-
-
Save notjuliee/fd2dd8620726e3dbc890e22e83068261 to your computer and use it in GitHub Desktop.
AHK4Tux
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 | |
# AHK For Linux | |
from sys import argv as args; | |
from subprocess import call; | |
import re; | |
regexes = { | |
"IfWinName\((.+)\)": "if [ $(xdotool getactivewindow getwindowname) = \"%s\" ]; then", | |
"EndIf": "fi", | |
"#.*": "", | |
"MouseMove\\((\\d+),(\\d+)\\)": "xdotool mousemove %s %s", | |
"MouseMoveR\\((\\d+),(\\d+)\\)": "xdotool mousemove_relative %s %s", | |
"Click\\(([1-5])\\)": "xdotool click %s", | |
"MouseDown\\(([1-5])\\)": "xdotool mousedown %s", | |
"MouseUp\\(([1-5])\\)": "xdotool mouseup %s", | |
"Type\\((.+)\\)": "xdotool type \"%s\"", | |
"Sleep\\((\\d+)\\)": "xdotool sleep %s", | |
"Press\\((.+)\\)": "xdotool key %s" | |
} | |
prefix = "#!/bin/bash\n# Generated using AHK4Tux\nmain(){\n"; | |
suffix = "\n}\nmain &"; | |
def main(): | |
toCompile = open(args[1], 'r').read(); | |
lines = toCompile.split("\n"); | |
compiledLines = []; | |
for line in lines: | |
cline = line; | |
addMe = False; | |
for regex in regexes: | |
match = re.search("^\\s*"+regex+"\\s*$", cline); | |
if not match: | |
continue; | |
addMe = True; | |
cline = cline.replace(match.group(0),regexes[regex] % match.groups()); | |
if addMe and cline != "": | |
compiledLines.append(cline); | |
with open(args[2], 'w+') as outFile: | |
outFile.write(prefix+";".join(compiledLines)+suffix); | |
call(["chmod","755",args[2]]); | |
def usage(): | |
print("Usage: %s <.ahk file to compile> <output filename>" % (args[0])); | |
return; | |
if __name__ == "__main__": | |
if (len(args) != 3): | |
usage(); | |
else: | |
main(); |
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
MouseMove(0,0) | |
Sleep(1) | |
Type(echo Hello world) | |
Press(Return) | |
# This is a comment | |
Sleep(1) | |
Type(echo Its alive) | |
Press(Return) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment