How to create a custom tasks.json or launch.json in VS Code that simply runs an executable and has no output?

Viewed 932

Please forgive me if this comes across as silly or dumb, but I'm new to vscode and getting back into programming in general and Ive run into this 'issue' and have hit a wall..

I'm trying to setup a task or a launcher for AutoHotKey scripts in VS Code which simply runs autohotkey from the commandline with the file location and a switch as an argument. Thats it. No output to analyze, nothing to actually debug. I have an extension installed which has a run script feature, but the way its coded doesnt account for there being spaces in directory or file names, so it doesnt work for me. No big deal I thought, I can figure out a way to do this myself.

I have created this task:

{
   "version": "2.0.0",
   "tasks": [
      {
         "label": "Run AutoHotKey Script",
         "type": "shell",
         "group": "none",
         "command": "autohotkeyu64.exe",
         "args": [
            "/r",
            "${file}"
         ],
         "detail": "Load script into AutoHotKeyU64.exe and run"
      }
   ]
}

I added the authotkey folder as a system path, and when I run the task it works great.

But, the terminal sits there thinking its still running a task - the task never ends. When I want to reload the script, I get a notification all the way down in the bottom corner saying the task is still running; do I want to terminate or restart.

So I thought maybe setting this up as a task is not the right thing and I tried to get it working the same way with launch.js, but it never actually opened autohotkey.. it doesnt give any errors, but it doesnt actually run the executable so I'm not sure where I went wrong, either way there is nothing to actually debug, no output for vs code to interpret.

Is there a way I can do this? I mean sure its just a little notification and an extra step I have to take... but theres gotta be a way, right? What exactly is VS Code looking for to terminate the task? How can I fudge this?

Any help greatly appreciated

Thanks

2 Answers

Well, I figured out a way, but Id still like to know if its possible with tasks or launching..

I discovered the command "workbench.action.terminal.sendSequence" and was able to set the args text to "autohotkeyu64 /r \"${file}\"" and applied a keybinding and it sends to the terminal, but then I have to focus on it and actually send the command..

So I tried workbench.action.terminal.runActiveFile, and since I have autohotkey on my system path and the file association, it actually runs the script by just passing it into the terminal, pretty cool. But for some reason, the args I set, in this case "/r" (which forces a reload of the script rather than a new instance and avoids a msgbox notification), didn;t work. VSCode has no problem with the argument, but it doesnt actually use them.

So long story short, I figured out I just need to add an option "#SingleInstance Force" to the top of my autohotkey scripts and it performs the reload automagically..

And all is well...

Would still love to hear any suggestions for other ways to accomplish this - Aside from writing an autohotkey script to do this HAH.

I feel kinda dumb for posting now that I figured a method out.. I honestly spent so long trying to do this, I honestly felt like I had no other choice but to swallow my pride and ask online.. but it seems thats the way it always goes...

I have problem to fully understand what you want to do or what is your real need, so excuse if my answer might not fit.

If you want to run in vscode a AHK script, I personally use code runner and ahk++ extensions. Here you have to setup the settings properly.

For me the settings.json looks like:

code runner settings:

"code-runner.executorMap": {   
        "ahk": "D:\\Programs\\AutoHotkey\\AutoHotkeyU64.exe"
        },

    "code-runner.executorMapByFileExtension": {
        ".ahk": "D:\\Programs\\AutoHotkey\\AutoHotkeyU64.exe"
        },

ahk++ settings:

"ahk++.showDebugButton": true,
"ahk++.executePath": "D:/Programs/AutoHotkey/AutoHotkeyU64.exe",
"ahk++.compilePath": "D:/Programs/AutoHotkey/Compiler/Ahk2Exe.exe",
"ahk++.helpPath": "D:/Programs/AutoHotkey/AutoHotkey.chm"
Related