v0p3r
v0p3r

Reputation: 43

How to create folder with files in project folder in visual studio code via AutoHotKey?

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

Answers (1)

lww
lww

Reputation: 661

Assuming that you started script manually and it's running in the tray,

enter image description here

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.

enter image description here

Upvotes: 1

Related Questions