Is there an AutoHotkey REPL? - autohotkey

I know that you can run and live-reload ahk scripts. And I've seen the scintilla-based editor that provides debugging. But, is there any kind of command-line-based REPL?
I was testing the statement to get the active window's process name and thought it would really helpful!
ahk> WinGet, active, ProcessName, A
powershell.exe

This may also be something like what you're looking for
Forum Topic link
GitHub link
Hope it helps

I open my AHK script NotePad (or Vim, or whatever). Then I add my test code as the first line. I have a hotkey defined to reload the script.
MsgBox, Hello World
^+r::
Reload
Return
So I edit, then Ctrl-s, then Ctrl-Shift-R, test code runs. Works pretty well.

Related

AHK for Save Dialog: Navigate to desktop and jump to field filename

I was using this Autohotkey script for a while:
; Windows Explorer Save Dialog
; hitting CTRL D goes to address bar, jumps to full desktop path, then goes to filename for the user to override
#IfWinActive ahk_class #32770
^D::
Send !D
String := "%UserProfile%\Desktop"
SendRaw %String%
Send {ENTER}
Send !D
return
#IfWinActive
It stopped working. Probably a Windows 10 update changed something in the file save dialog.
Now using the script above (hitting CTRL+D) still opens the desktop location, but goes to the top right "Desktop Search" (instead of the filename).
Also changing the last Send !D to Send !N did not help.
Also Send {TAB} does not help, Windows ignores it. The focus seems to be stuck to the Search field.
After the discussion in comments, I was actually able to reproduce the issue you're encountering and found the issue.
The Alt+N hotkey in the save file dialog to switch focus to file name field indeed doesn't seem to work if the focused control never left any of the text input controls. By setting the focused control at least once to something other than one of the text input controls, then the Alt+N hotkey seems to work as expected.
Ok, so here's the working code.
^d::
ControlFocus, DirectUIHWND2, A
SendInput, % "!d%userprofile%\Desktop{enter}!n"
return
So first we're focusing the DirectUIHWND2 control, could've used an other control in the save file dialog as well, doesn't matter which one we use.
And if you don't know how to figure out windows' controls, one easy way is to use "Window Spy". It's a neat little AHK script that comes with every AHK installation.
You'll find it from your AHK install directory.
Should be called C:\Program Files\AutoHotkey\WindowSpy.ahk. Or if you have an older AHK installation, it may also be a compiled script file named AU3_Spy.exe (or something like that, I forget)
And the A parameter in the ControlFocus command means the active window.
And then I used just one send command. No need to use multiple send commands, or create some variable, as you do in your code.
And also used !d and !n instead of !D and !N.
Don't use capital letters in send commands, unless you actually want them.
!D and !N actually send Ctrl+Shift+D and Ctrl+Shift+N, instead of Alt+D and Alt+N, which is what I assume you actually were after.
Also, used SendInput instead of just Send. SendInput is the preferred method due to it being faster and more reliable (more about this from the documentation)
Though, one concern I have, is maybe it could even be too fast. Seems work fine for me every single time, but if you were to have trouble, you can maybe split it up to multiple commands, adding a bit of Sleep in between. Or maybe could even switch back to Send and use SetKeyDelay.
Another approach for this, could be with using control set -commands.
E.g. first focusing a control, as I did in my code, and then using e.g ControlSetText.

How to install/run autohotkey without admin privileges?

I followed this tutorial: http://www.thenickmay.com/articles/how-to-install-autohotkey-without-admin/
At Step #6, I opened AutoHotkeyU64.exe and it opened up the help file for AutoHotKey.
Then I went through the tutorial and tried out the script they give:
^j::
Send, My First Script
return
I saved this as tutorial.ahk, then opened a new notepad file and pressed ctrl+j. Nothing happened.
Anyone know what's going on? I've never used autohotkey before, btw.
Since I was able to install it normally, I can't say for certain, but I believe there is a skipped step (or two) in the instructions.
After step 5, run (double-click) your .ahk script. If you get a message asking
"How do you want to open this file", choose "More apps", then "Look for another app on this PC" (see image below), then navigate to and choose AutoHotkey.exe or AutoHotkeyU64.exe. Be sure to keep the checkbox checked to "Always use this app to open .ahk files" so that you only need to do this once on your machine.
I am late to the party and dunno if anyone's left drinking here, but I want to run ahk just to fix that darn copy/paste function on cmd/erp ... Hope this works

" #SingleInstance force " is being ignored

SingleInstance force
is supposed to prevent the popup when I tell the script to reload... but it doesn't. I'm still getting the warning that a copy of the script is already running. Thoughts?
Without seeing your code, there are a few things I can think of that might be interfering. The first is that there may be a typo. Please verify that it is exactly #SingleInstance force. Another thing could be that it is not placed near the beginning of the script; possibly after a Return. Finally, from the help file,
AutoHotkey relies on the title of the script's main window to
identify other running instances of the script.
Is this script calling another script or is there anything the might affect the script name? If none of these things helps, it might be a good idea to post your code or at least a portion of it so we can better see what's going on.

Calling elisp code when awakening from sleep

I'd like to configure emacs a little differently when coming in over remote desktop. I can detect the rdp session, but I'd like to automatically run the function that checks when emacs wakes from sleep. I believe Windows issues a PBT_APMRESUMESUSPEND event when awakening because of user activity -- is there a way to hook this from within emacs?
This would be for emacs 24.4 on Windows. Some code or a pointer to the right documentation would be great. I've looked but am not seeing anything -- maybe I'm not looking in the right place. Thanks in advance.
I don't know of any hooks that are triggered in your situation, would it be possible to solve your situation using the input focus hooks?
Specifically, focus-in-hook.

Run a program automatically on script start-up

I am trying to make an AHK script open another program everytime it is started. The problem is, I don't want this to happen if that other program is already opened.
Here's what seems to be supposed to be working, but isn't : (this section is placed at the very top of my script)
SetTitleMatchMode, 2
#IfWinNotExist, Microsoft Excel - myExcelFile.xls
Run C:\myExcelFile.xls
#IfWinExist
;REST OF MY SCRIPT GOES HERE
What should be happening :
If the window "Microsoft Excel - myExcelFile.xls" is not opened, run it. If not, do not.
What is happening :
Whether it is opened or not, it will try to run it again.
So yeah, even though I had read the documentation, I had understood that the difference between #IfWin and IfWin was whether they were used inside or out of a specific hotkey. To my understanding, "creates context-sensitive hotkeys and hotstrings" also included "context-sensitive auto-execution" (when code is not inside a hotkey)
Indeed I was wrong and the solution is to remove the #.