Page 1 of 1
I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")
Posted: 26 Apr 2024, 23:14
by alawsareps
Code: Select all
#Requires AutoHotkey v2.0
f1:: {
; click any ahk file on desktop
; Send("^c") ; copy the file path
Run("C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%A_Clipboard%")
return
}
Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%") Topic is solved
Posted: 27 Apr 2024, 00:25
by boiler
You’re not using expression syntax correctly. First, you don’t put
% around variables. And you don’t put variables inside quotes. And unlike legacy syntax in v1, you have not put quotes in the strings themselves and separated them with a space; you have concatenated two strings (that don’t contain any quotes) without a space between them. Should be:
Code: Select all
Run '"C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe" "' A_Clipboard '"'
To see the difference between the two, run the following script:
Code: Select all
#Requires AutoHotkey v2.0
A_Clipboard := 'hello'
str1 := "C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%A_Clipboard%"
str2 := '"C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe" "' A_Clipboard '"'
MyGui := Gui()
MyGui.SetFont('s12','Consolas')
MyGui.Add('Text',, str1 '`n' str2)
MyGui.Show
Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")
Posted: 27 Apr 2024, 09:32
by alawsareps
@boiler
What I'm trying to achieve is to be able to open any AHK file in VScode.
Code: Select all
#Requires AutoHotkey v2.0
f1:: {
Send("^c") ; copy path of chosen file
sleep(100)
Run("C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe " A_Clipboard)
return
}
...but this only works fine with files with not spaces.
If I try to open a file name "hello world.ahk", VScode will open two files, "hello" and "world.ahk".
Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")
Posted: 27 Apr 2024, 09:40
by boiler
Well, when you make no attempt to implement what I showed you regarding quotes around it, are you surprised that it didn’t help?
Did you see where I said “Should be:”? Is there a reason you ignored it? I showed you the exact line to use and you did something else.
Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")
Posted: 27 Apr 2024, 09:59
by boiler
@alawsareps — To make it crystal clear, replace your
Run line with this one:
Code: Select all
Run '"C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe" "' A_Clipboard '"'