正在创建AutoHotKey快捷方式,以便在文件资源管理器中的特定文件夹中打开powershell并执行某些代码



我想创建一个AutoHotKey脚本,它将打开powershell控制台(在文件资源管理器窗口中打开的同一文件夹中(并执行以下代码:

$nrRef = [ref] 0
Get-ChildItem -Filter *.jpg | Rename-Item -Newname {
'{0}_{1:d3}.jpg' -f (Split-Path -Leaf $_.DirectoryName), ++$nrRef.Value}

然后关闭powershell控制台窗口。

注意:启动AHK脚本的快捷方式:在资源管理器窗口的特定文件夹中按下Ctrl+Shift+LeftMouseButton

#NoEnv
#SingleInstance Force
#IfWinActive, ahk_class CabinetWClass ; explorer
; Ctrl + Shift + LeftMouseButton
^+LButton::
ActivePath := GetExplorerActivePath()
code =
(
$nrRef = [ref] 0
Get-ChildItem -Filter *.jpg | Rename-Item -Newname {
'{0}_{1:d3}.jpg' -f (Split-Path -Leaf $_.DirectoryName), ++$nrRef.Value}
)
Run powershell.exe -windowstyle hidden -Command &{%code%}, %ActivePath%
return
#IfWinActive
; get the path of the active file explorer:
GetExplorerActivePath(){
WinGetTitle, ActiveTitle, A
If InStr(ActiveTitle, "")  ; If the full path is displayed in the title bar (Folder Options)
ActivePath := ActiveTitle
else
If InStr(ActiveTitle, ":") ; If the title displayed is something like "DriveName (C:)"
{
ActivePath := SubStr(ActiveTitle, -2)
ActivePath := SubStr(ActivePath, 1, -1)
}
else ; If the full path is NOT displayed in the title bar 
; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
for window in ComObjCreate("Shell.Application").Windows
{
try ActivePath := window.Document.Folder.Self.Path
SplitPath, ActivePath, title
If (title = ActiveTitle)
break
}
return ActivePath
}

https://autohotkey.com/docs/commands/_IfWinActive.htm

相关内容

  • 没有找到相关文章

最新更新