【发布时间】:2019-06-06 14:33:31
【问题描述】:
我正在尝试制作一个脚本,该脚本将成为某些文件夹结构生成的快捷方式。基本上,我有一个模板 .ahk 脚本,我已经适应了我的需要,还有一个简单的 .bat 脚本,可以创建我需要创建的文件夹。
.ahk 脚本调用 .bat 脚本。问题是,.ahk 脚本将 .bat 脚本位置放入剪贴板,并应将其粘贴到 .ahk 在我执行快捷方式的目录中打开的 cmd 窗口中。但是,粘贴功能不起作用。 CMD终端显示如下:
F:\Documents\Scripts\Template Scripts\Reference Media>v
'v' is not recognized as an internal or external command, operable program or batch file.
这是我的 .ahk 脚本:
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:\ "
}
}
这是它调用的 .bat 脚本:
@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"
.ahk 脚本中棘手的部分是:Send ^v {Enter}
我不明白为什么它不自动粘贴。当我手动按 ctrl+v 时,它会粘贴字符串,并按预期执行 .bat 脚本。
我已经尝试使用 Send {Ctrl down} {v} {Ctrl up} {enter} 它仍然在 cmd 窗口中返回同一行。
有解决方案的想法吗?
谢谢。
【问题讨论】:
-
我几乎可以肯定,如果您在该行之前和之后放置更多 Sleep (您已注释掉一个),问题将得到解决。只需将两个值都设为 1000 毫秒,然后看看它是如何工作的。
标签: batch-file autohotkey