在命令行当中用VSCode 打开一个文件夹,同时打开一个文件 + AutoHotkey 用 VSCode,Sublime打开选中的文件
Opening a Folder and File in Vscode from Terminal | JagaScript
code path_to_foder --goto path_to_file
AHK
注意把VSCode的根目录添加到环境变量(并且用code.exe 调用),否则可能无法Run
CapsLock & s:: ; sublime
folder := GetActiveExplorerPath()
file := GetSelectedFilePath()
if(folder != "")
{
Run, % "subl """ . file . """ -a """ . folder . """ ", , Hide, ; add folder
}
else if(file != "")
{
Run, % "subl """ . file . """" , Hide, ; without folder
}
Return
CapsLock & v::
folder := GetActiveExplorerPath()
file := GetSelectedFilePath()
cmd := "code -n """ . file . """ -a """ . folder . """"
if(folder != "")
{
; Run, % "code"
Run, % "code """ . folder . """ --goto """ . file . """", , Hide, ; add folder
}
else if(file != "")
{
Run, % "code -n """ . file . """" , Hide, ; without folder
}
; code -n "D:\Data\Programs\UserData\Caesium\1.jpg" -a "D:\Data\Programs\UserData\Caesium"
Return
GetActiveExplorerPath()
{
explorerHwnd := WinActive("A")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
folder := window.Document.Folder.Self.Path
return folder
}
}
}
}
GetSelectedFilePath()
{
hwnd := WinExist("A")
for Window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd) {
Selection := Window.Document.SelectedItems
for Items in Selection
Path_to_Selection := Items.path
}
Return Path_to_Selection
}
本博文本意在于记录个人的思考与经验,部分博文采用英语写作,可能影响可读性,请见谅
本文来自博客园,作者:ZXYFrank,转载请注明原文链接:https://www.cnblogs.com/zxyfrank/p/15098554.html