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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 38
Joined: 20 Jul 2016, 09:28

I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")

26 Apr 2024, 23:14

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
}
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

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

27 Apr 2024, 00:25

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
alawsareps
Posts: 38
Joined: 20 Jul 2016, 09:28

Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")

27 Apr 2024, 09:32

@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".
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")

27 Apr 2024, 09:40

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.
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: I want to open in VSCODE any file I copied. Code doesn't work: Run("C:\Users\jethr\...\Code.exe" "%A_Clipboard%")

27 Apr 2024, 09:59

@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 '"'

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: DavidP, mikeyww, TomDonovan, vanove and 92 guests