This is how I can successfully open only the VS-Code app:
^!h::If !FileExist(code := StrReplace(A_AppData, "Roaming", "Local\Programs\Microsoft VS Code\Code.exe"))
MsgBox, 48, Error, File not found.\n`n%code%`
Run, %code%
return
However, here is my issue:
I use Stardock Groupy on my computer. Groupy groups any open window on your computer into tabs; an Explorer window, application, etc. You can group specific folders and files and save them as a custom group, which Groupy will save as a ".groupy" file. The file runs by selecting it within the Groupy "Saved Groups" dropdown, or you can double-click the ".groupy" file.
I have a custom ".groupy" file that opens (and groups into tabs) an Excel file and a text file that runs via VS-code. When I open my group, two things open successfully and get grouped into tabs: Excel and VS-Code.
Three ways successfully open both Excel and VS-Code into a tabbed group:
Within Groupy's dropdown
Double-clicking the ".groupy" file
Running the following command in cmd:
%AppData%\Groupy\CROSS_EXCEL_VS.groupy
I want to run this ".groupy" file via AHK, but when I do, the file runs, but only the Excel file opens. No matter how I try to run the .groupy file via AHK, VS-Code doesn't run at all.
Here are the various ways I've tried:
001:
run, %A_AppData%\Groupy\CROSS_EXCEL_VS.groupy
002:
If !FileExist(groupy := A_AppData "\Groupy\CROSS_EXCEL_VS.groupy")
MsgBox, 48, Error, File not found.\n`n%groupy%`
Run, %groupy%
003:
Run "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
004:
Run, C:\Program Files (x86)\Stardock\Groupy\Groupy32.exe
, "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
005:
run cmd /k "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
006:
commands="C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
runwait, %comspec% /c %commands%
007:
run C:\Windows\System32\cmd.exe /C "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy",,hide
What can the problem be?
Found a way. I set C:\Program Files\AutoHotkey\AutoHotkey.exe compatibility setting to "Run this program as an administrator" and all works fine.
Related
If my script is run within vscode, it want it to open a .txt file in a new tab in vscode. Else, open the folder containing the file. However, the current "code" command opens it in the terminal window instead of a new edit tab.
if ($env:TERM_PROGRAM -eq 'vscode') {
code 'C:\temp\_Release_Evidence\test.txt'
}
else {
explorer 'C:\temp\_Release_Evidence'
}
Normally, code refers Visual Studio Code's CLI, which is assumed to be in one of the directories listed in $env:PATH:
On Windows, it refers to the code.cmd batch file that serves as the CLI entry point.
On Unix-like platforms it refers to a code Bash script.
Its default behavior is to open a given file as a new tab in the most recently activated Visual Studio Code window (which, when run from inside Visual Studio Code, is by definition the current window).
If that doesn't happen for you, perhaps code refers to a different executable on your machine:
To avoid ambiguity, use the full CLI path instead, which, however, requires you to know Visual Studio Code's install location; typical CLI locations are:
Windows: $env:LOCALAPPDATA\Programs\Microsoft VS Code\bin\code.cmd
macOS: /usr/local/bin/code
Linux: /usr/bin/code
On Windows, something as simple as including the filename extension in the invocation - i.e., code.cmd - may help.
However, assuming you're using the PIC (PowerShell Integrated Console), a specialized PowerShell shell that comes with the PowerShell extension for Visual Studio Code, a workaround that also performs better, because it doesn't require launching a child process:
The PIC comes with the psedit command (an alias for the Open-EditorFile function), which quickly opens one or more files in a tab in the current Visual Studio Code window.
Caveat: As of version v2022.5.1 of the PIC, specifying multiple files only works meaningfully if they are individually enumerated, as literal paths. If you try to use a wildcard pattern or a directory path, all matching files / files in the directory are uselessly opened in sequence in a single tab.
Thus, you could use the following:
if ($env:TERM_PROGRAM -eq 'vscode') {
# Use `psedit`, if available; `code` otherwise.
$exe = if ((Get-Command -ErrorAction Ignore psedit)) { 'psedit' } else { 'code' }
& $exe 'C:\temp\_Release_Evidence\test.txt'
}
else {
explorer 'C:\temp\_Release_Evidence'
}
I can't reproduce this or explain why this might occur on your system. Running the following whether in the PowerShell Integrated Terminal (which #mklement0 explained succinctly) or a standard PowerShell terminal in VS Code's Terminal pane should open the file in a new tab where file contents are normally displayed:
code /path/to/file.txt
A suitable workaround may be to get the contents of a text file and pipe them in via STDIN. We can do this by adding a hyphen - as an empty parameter to code when piping data to it:
# Tip: Use the gc alias for Get-Content
Get-Content /path/to/file.txt | code -
You can then use Save As... to save the file to its intended target once you make your changes. You will need to use Ctrl+C in the terminal to close the input stream if you need to run additional commands before closing the file or saving to a one.
Even if this isn't a suitable workaround for you, it's a handy tip in other scenarios. For example, the following command will open documentation for Get-Process inside VSCode:
Reminder: Don't forget to hit Ctrl+C in the terminal once the content finishes populating to be able to run additional commands, or close the temporary file buffer.
Get-Help Get-Process -Detailed | code -
How can this procedure be done with ahk script
If I press Ctrl+Q
It opens chrome.
Selects Mayank Profile, enter image description here, opens www.google.com and www.yahoo.com in it.
As of now Mayank chrome is running, then Selects Julia profile and opens www.gmail.com and www.yahoomail.com.
As of now Now Three chrome will be opening right, One the chrome that is launched firstly, Mayank secondly, Julia the third. As I have to work with these two chromes(2nd and 3rd)
It closes the first chrome.
and I end up having only two chromes opened and julia is activated which contains www.gmail.com and www.yahoomail.com as shown in the picture.
enter image description here
Note: All this happens if I press Ctrl+Q
You can set a flag for chrome.exe when you launch it, so that it starts in a specific profile. An example of the command is this:
chrome.exe --profile-directory="Default" https://stackoverflow.com
The above code will launch this site, while using the profile-directory "Default" which is the default profile for Chrome. You can substitute "Default" with any other profile-directory. However, the name for the directory is not the same as the one set in the profile inside of the browser. All manually created profile-directories are named Profile # where # is a digit increasing from 1 for each created profile.
For example, I have created the following two profiles:
The default path for the Profiles is:
C:\Users\<user>\AppData\Local\Google\Chrome\User Data\
Looking in the folder I can find two folders named:
Profile 1\
Profile 2\
To make it easier to determine what user corresponds with which folder, you can open the file Preferences inside of each of those folders. Inside of that JSON-File, you can search for the key "name": which will contain the name you've set inside of the GUI.
After you've determined what folders are for the profile you want, then we can create the hotkey we're after:
^q::
Run, chrome.exe --profile-directory="Default" https://stackoverflow.com/
Run, chrome.exe --profile-directory="Profile 1" https://superuser.com/
Run, chrome.exe --profile-directory="Profile 2" https://www.google.com/ https://www.duckduckgo.com/
I want to be able to launch the script file .ahk in edit mode (in sublime), reload, pause etc script via a windows shortcut.
Basically I want some of the following commands, (edit, reload):
Is there a flag like /e or --edit --reload that is specified in the windows shortcut editor dialog & command line so as to launch the any of above commands:
Thanks
There are built-in commands for both Reload and Edit
You can just assign hotkeys to the commands, to execute them directly inside of the code:
^!r::Reload ; Ctrl+Alt+R
^!e::Edit ; Ctrl+Alt+E
Is it possible to operate. Exe application from command promt.?
I have a problem where i have tologin to my window application from command promt.
I can open the application but ubable to click file menu(login, save, etc).
You should be able to alt + f when the exe application window is selected
When Executable writes to console (using the -console option), if I press "enter" a second time, it bring me back to the command prompt even though Executable is still running in the background. How we can force it to output everything to the console and only when done should it return to command prompt?
The installer on windows is a GUI executable, it cannot make the console wait for the process to finish. There are two ways around this:
1) Select the "Windows console executable" property of the installer on the Installer->Screens & Actions step. Drawback: When starting the installer from the explorer, a console will be opened.
2) Start the installer on the command line like this:
cmd /c installer.exe -c