Reputation: 43
I created script via ahk that create folder with 2 files on shortcut when explorer is active. Is it possible to run this script inside project explorer in visual studio code?
#IfWinActive ahk_class CabinetWClass
!1::openGui()
openGui() {
Js := "import styled from 'styled-components';`n`nexport const Wrapper = styled.div````;"
WinGetActiveTitle, MyWin
Gui, New
InputBox, Name, Input folder name
if ErrorLevel
return
else
Jsx =
(
import React from 'react';
import { Wrapper } from './%Name%.styles';
const %Name% = () => {
return <Wrapper>%Name%</Wrapper>;
};
export default %Name%;
)
FileCreateDir, %MyWin%\%Name%
FileAppend, %Jsx%, %MyWin%\%Name%\%Name%.jsx
FileAppend, %Js%, %MyWin%\%Name%\%Name%.styles.js
}
return
Upvotes: 1
Views: 197
Reputation: 661
Assuming that you started script manually and it's running in the tray,
using ahk Window Spy you can verify vs studio window value to be ahk_exe devenv.exe
so you can use for example if WinExist("ahk_exe devenv.exe")
instead #IfWinActive ahk_class CabinetWClass
which is to detect windows explorer window not vs studio.
in summary:
if WinExist("ahk_exe devenv.exe")
!1::openGui()
openGui() {
Js := "import styled from 'styled-components';`n`nexport const Wrapper = styled.div````;"
WinGetActiveTitle, MyWin
Gui, New
InputBox, Name, Input folder name
if ErrorLevel
return
else
Jsx =
(
import React from 'react';
import { Wrapper } from './%Name%.styles';
const %Name% = () => {
return <Wrapper>%Name%</Wrapper>;
};
export default %Name%;
)
FileCreateDir, %MyWin%\%Name%
FileAppend, %Jsx%, %MyWin%\%Name%\%Name%.jsx
FileAppend, %Js%, %MyWin%\%Name%\%Name%.styles.js
}
return
now when i press alt + 1
i can create folder.
Upvotes: 1