Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

How to execute Autohotkey AHK script from Chrome user script?

  • Please log in to reply
2 replies to this topic
  • Members
  • 2 posts
  • Last active: Nov 05 2015 03:14 AM
  • Joined: 30 Oct 2015

I would like to be able to call Autohotkey script from javascript user script in Chrome. Is this possible?

  1. Autohotkeys has many useful functions in including the ability to search for predefined images on the screen which i would like to be able to call upon.

  2. I would also like to "send clicks" to external domain iframes/flash, which i believe browser security will block if issued from userscript, but I'm hoping via Autohotkeys I can send clicks at a windows level and have Chrome respond to those.

  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Browser security also tends to block you from accessing files on a PC. I don't know if you can get a javascript code to launch an AHK script. What you could possibly do though is have your AHK script running and monitoring for javascript to do something such as change the title of the window (I think that's possible) as a que for it to execute command X.


Here's how I would do it:


SetTitleMatchMode, 1
SetTimer, monitor, 500 ; loop might be better, but I'll try set timer here
WinWaitActive, tampermonkeytitle ; the full title would be set as something like tampermonkeytitle cruiser - Google Chrome
WinGetTitle, name, A
StringTrimLeft, name, name, 18 ; take off the "tampermonkeytitle " from the name
StringTrimRight, name, name, 16 ; take off the " - Google Chrome" from the name
GoSub %name%
MsgBox You executed the line cruiser


And then your javascript should change the page's title (or window if you get that much control, I don't think you do) and include the unique prefix "tampermonkeytitle " and whichever label you would like to execute.


Now, the matter of feeding AHK commands back into javascript gets much trickier... The best I've done is use AHK to modify the javascript in my script manager extension (Scriptish in firefox) and refresh the page to execute changes.




OR, if you can, you can use COM which can explicitly work with websites in Internet Explorer and the syntax is similar to javascript, so it should be possible to translate your javascript code into an AHK script with COM and just have everything run from one AHK script.


Check out the Tutorials section of this forum for a few guides on using COM in Internet Explorer.

  • Members
  • 2 posts
  • Last active: Nov 05 2015 03:14 AM
  • Joined: 30 Oct 2015

Thanks some food for thought. I do use tampermonkey as it happens as vehicle for "web automation". What I'm trying to do is extend the javascript with some of AHKs nifty features. You've given me an idea mentioning file access. May be i could have an AHK script running to act as a "service", if i can get javascript to access a file - which i can do with tampermonkey i believe - it could request the AHK service to perform actions using the file as an interface, react accordingly and pass information back to the javascript! So for example, the userscript would write a request in the file to do an imagesearch on the current webpage, AHK would react, find the image and write success/fail back to the interface file :)


Update: My assumption that TM can access a local file appears to be wrong :/, but it can read/write tags/values to a SQlite database assigned to the userscript. This would serve as the interface to AHK :)