-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvscode.ahk
36 lines (35 loc) · 1.06 KB
/
vscode.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
; AutoHotKey, 通过快捷键ctrl+alt+c打开选中文件或文件夹所在的VS Code窗口
GetSelectedPath()
{
global ClipSavedContent ; Renamed to avoid conflict with built-in Clipboard variable
; 保存当前剪贴板内容
ClipSavedContent := ClipboardAll
; 发送快捷键复制选中文件路径
Send "^c"
Sleep 500 ; 等待剪贴板更新
; 检查剪贴板内容是否为空或不符合路径格式
if (Clipboard != "" && (InStr(Clipboard, ":") || InStr(Clipboard, "\"))) ; 检查是否包含路径分隔符
{
selectedPath := Clipboard
}
else
{
selectedPath := ""
}
; 恢复剪贴板内容
Clipboard := ClipSavedContent
return selectedPath
}
^!c::
{
; 获取当前选中的文件或文件夹路径
selectedPath := GetSelectedPath()
if (selectedPath = "")
{
MsgBox "No file or folder selected, or unable to obtain a valid path."
return
}
; 启动 VS Code
Run, %ComSpec% /C code "%selectedPath%", , Hide
Return
}