code "C:\Users\abc\Downloads\mytextfile.txt"
it works perfectly, unfortunately not this code line in ahk
Code: Select all
run,% "C:\Users\abc\AppData\Local\Programs\Microsoft VS Code\Code.exe " "C:\Users\abc\Downloads\mytextfile.txt"
Code: Select all
run,% "C:\Users\abc\AppData\Local\Programs\Microsoft VS Code\Code.exe " "C:\Users\abc\Downloads\mytextfile.txt"
Code: Select all
#Requires AutoHotkey v1.1.33
EnvGet localAppData, LOCALAPPDATA
downloads := downloadsDir()
filePath := downloads "\test.txt"
Run % localAppData "\Programs\Microsoft VS Code\Code.exe """ filePath """"
downloadsDir() {
; Adapted from teadrinker: https://www.autohotkey.com/boards/viewtopic.php?p=284248#p284248
Static FOLDERID_Downloads := "{374DE290-123F-4565-9164-39C4925E467B}"
RegRead v, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, % FOLDERID_Downloads
VarSetCapacity(downloads, (261 + !A_IsUnicode) << !!A_IsUnicode)
DllCall("ExpandEnvironmentStrings", "Str", v, "Str", downloads, "UInt", 260)
Return downloads
}
If the program/document name or a parameter contains spaces, it is safest to enclose it in double quotes (even though it may work without them in some cases). For example, Run, "My Program.exe" "param with spaces".
Code: Select all
#Requires AutoHotkey v1.1.33
EnvGet localAppData, LOCALAPPDATA
downloads := downloadsDir()
filePath := downloads "\test.txt"
SoundBeep 1500
RunWait % ComSpec " /c code """ filePath """",, Hide
downloadsDir() {
; Adapted from teadrinker: https://www.autohotkey.com/boards/viewtopic.php?p=284248#p284248
Static FOLDERID_Downloads := "{374DE290-123F-4565-9164-39C4925E467B}"
RegRead v, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, % FOLDERID_Downloads
VarSetCapacity(downloads, (261 + !A_IsUnicode) << !!A_IsUnicode)
DllCall("ExpandEnvironmentStrings", "Str", v, "Str", downloads, "UInt", 260)
Return downloads
}
Million thanks @mikeyww WORKS like a charmmikeyww wrote: ↑29 Mar 2023, 06:03Good point, Russ.
I think that the replication of the run line is more straightforward, too, as ComSpec should handle the command the same way.
Code: Select all
#Requires AutoHotkey v1.1.33 EnvGet localAppData, LOCALAPPDATA downloads := downloadsDir() filePath := downloads "\test.txt" SoundBeep 1500 RunWait % ComSpec " /c code """ filePath """",, Hide downloadsDir() { ; Adapted from teadrinker: https://www.autohotkey.com/boards/viewtopic.php?p=284248#p284248 Static FOLDERID_Downloads := "{374DE290-123F-4565-9164-39C4925E467B}" RegRead v, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, % FOLDERID_Downloads VarSetCapacity(downloads, (261 + !A_IsUnicode) << !!A_IsUnicode) DllCall("ExpandEnvironmentStrings", "Str", v, "Str", downloads, "UInt", 260) Return downloads }