"Edit This Script" opens multiple empty files

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
StarNamer
Posts: 1
Joined: 22 Oct 2021, 06:20

"Edit This Script" opens multiple empty files

Post by StarNamer » 22 Oct 2021, 06:46

[Moderator's note: Topic moved from Bug Reports.]

On my work computer, I have OneDrive for Business which, for historical reasons I believe, appears in Explorer as "OneDrive - European Metal Recycling" (hr name of the company I work for. My Documents folder is mapped to the Documents folder in OneDrive, so the default AutoHotKey.ahk is located there. I use VSCode as my default text editor.

If I right click on the AutoHotKey system tray icon and click "Edit This Script", VSCode opens five tabs named "OneDrive", "-", "European", "Metal" and "AutoHotKey.ahk". Four of the tables are empty files; the AutoHotKey.ahk seems only to have three default lines in it. The AutoHotKey.ahk file opened is not "D:\OneDrive - European Metal Recycling\Documents\AutoHotKey.ahk", which is the originally loaded script, but "D:\OneDrive - European Metal Recycling\Documents\Recycling\Documents\AutoHotKey.ahk". Also, the "OneDrive" tab names the file as "D:\OneDrive" while the other three are in the Documents folder. None of the files on the opened tabs exists.

Clearly VSCode is being passed the unquoted filename and interpreting the value as five filenames instead of one.

Is there any workaround for this other than ignoring "Edit This Script" and opening the default AutoHotKey.ahk explicitly?

I've looked at the source, but I program in C# rather than C++ so a fix isn't obvious to me.

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: "Edit This Script" opens multiple empty files

Post by safetycar » 22 Oct 2021, 08:43

Sounds a bit weird to me, I never had this issue.
Do you have the some customization on windows that makes edit open in vscode instead of notepad?
Edit: I had written something else but there's a better answer below mine.
Last edited by safetycar on 23 Oct 2021, 02:07, edited 1 time in total.

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: "Edit This Script" opens multiple empty files

Post by lexikos » 22 Oct 2021, 23:48

"Edit This Script" just calls ShellExecuteEx, specifying the "edit" verb and path of the file. The shell (i.e. the OS) is responsible for looking up the command and executing it. Since you are obviously not using the default command created by the AutoHotkey installer (which registers notepad.exe as the script editor), you are responsible for registering the correct command, and whatever program is being launched is responsible for its own behaviour. This is not a bug in AutoHotkey and cannot be fixed by editing AutoHotkey's source code.

I can think of a few possible causes for the behaviour you describe:
  1. The command in your registry is missing quote marks around the file path (which is usually represented as %1 or %l in the registry).
  2. The command in your registry is incorrect for the program being executed (VSCode).
  3. The program being executed (VSCode) has a bug.
There is an example in the help file for using a script to change the default editor. You may try this to write a command which correctly encloses the path in quote marks. (This assumes the editor follows common convention, which appears to be the case for VSCode.)

If that fails, I suggest using Task Manager to check the actual command line that VSCode is receiving. If it is receiving a path wrapped in quote marks and still splitting it up, I presume VSCode is at fault. If it is not receiving the appropriate command line, also check that the default value of HKCR\.ahk is AutoHotkeyScript.

Post Reply

Return to “Ask for Help (v1)”