I'm trying to make a script that will be a shortcut for some folder structure generation. Basically I have a template .ahk script that I have adapted to my needs, and a simple .bat script that creates the folders that I need created.
The .ahk script, calls upon the .bat script. The issue is, the .ahk script puts the .bat script location into clipboard, and should paste it into the cmd window that the .ahk opens in the directory that I execute the shortcut in. However, the paste function doesn't work. The CMD terminal shows the following:
F:\Documents\Scripts\Template Scripts\Reference Media>v
'v' is not recognized as an internal or external command, operable program or batch file.
This is my .ahk script:
SetTitleMatchMode RegEx
return
; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass
; create new text file
;
#t::Send !fwt
; open 'cmd' in the current directory
;
#c::
OpenCmdInCurrent()
return
#IfWinActive
; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenCmdInCurrent()
{
; This is required to get the full path of the file from the address bar
WinGetText, full_path, A
; Split on newline (`n)
StringSplit, word_array, full_path, `n
; Find and take the element from the array that contains address
Loop, %word_array0%
{
IfInString, word_array%A_Index%, Address
{
full_path := word_array%A_Index%
break
}
}
; strip to bare address
full_path := RegExReplace(full_path, "^Address: ", "")
; Just in case - remove all carriage returns (`r)
StringReplace, full_path, full_path, `r, , all
IfInString full_path, \
{
Run, cmd /K cd /D "%full_path%"
WinWait, ahk_exe cmd.exe
ClipSaved := ClipboardAll ; save the entire clipboard to the variable ClipSaved
clipboard := "" ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
clipboard = ( call "F:\Documents\Scripts\Template Scripts\CreateFolderTemplate.bat" ) ; copy this text:
ClipWait, 2 ; wait max. 2 seconds for the clipboard to contain data.
if (!ErrorLevel) ; If NOT ErrorLevel, ClipWait found data on the clipboard
;Sleep 250
Send ^v {Enter} ; paste the text
Sleep 300
clipboard := ClipSaved ; restore original clipboard
ClipSaved = ; Free the memory in case the clipboard was very large.
return
}
else
{
Run, cmd /K cd /D "C:\ "
}
}
And this is the .bat script it calls upon:
@echo off
md Approvals
md "Behind The Scenes"
md "Client Notes"
md "Delivery/YYYY-DD-MM"
md "Other Media"
md "Personal Notes"
md "Project Files"/"Capture One"
md "Project Media (if applicable"
md "Production Media"
md "Reference Media"
cd "Production Media"
md "Media From Client"
md "Other Media"
The tricky part in the .ahk script is: Send ^v {Enter}
I can't understand why it doesn't paste it automatically. When I press ctrl+v manually, it pastes the string, and it executes the .bat script as it is supposed to.
I've tried doing it with Send {Ctrl down} {v} {Ctrl up} {enter} it still returns the same line in the cmd window.
Any ideas for a solution?
Thanks.