3

I'm trying to run an autohotkey (ahk) script in Python 2.7 but nothing seems to work. All online sources I've found are either outdated or overly complicated.

Has anyone found a way of doing this? I just want to run a couple of simple scripts that activates windows and opens applications. E.g:

IfWinExist, Command Prompt - python ...
    WinActivate

Update:

I've tried downloading pyahk:

ahk.start() # Ititializes a new script thread
ahk.ready() # Waits until status is True
ahk.execute(mw._['cwd']+"winActivate_cmd.ahk") # Activate cmd window

error: can't load autohotkey.dll

as well as trying this:

import win32com.client # Import library / module
dll = win32com.client.Dispatch("AutoHotkey.Script") #Creating DLL object?
dll.ahktextdll() #no idea what this is doing...        
dll.ahkExec("WinActivate, Command Prompt - python")

pwintypes.com_error invalid class string

Jonathan H
  • 141
  • 1
  • 12

1 Answers1

4

It seems like you should be able to just launch autohotkey with the script as a parameter using subprocess:

subprocess.call(["path/to/ahk.exe", "script.ahk"])

You'd have to check the autohotkey docs but this seems like it ought to work.

Alex Van Liew
  • 1,339
  • 9
  • 15
  • That worked! Thanks. Didn't think it'd be that easy :) Also, turns out my .ahk file didn't actually work but I've just tried it on a simple hello world – Jonathan H Apr 15 '16 at 16:56
  • No problem! Occam's Razor and all that; sometimes the simplest solution is the best one! – Alex Van Liew Apr 15 '16 at 16:59