Autohotkey个人即用脚本分享(持续更新ing)

本楼为文件管理器页面脚本

1. 调用spacesniffer,对当前路径进行透析查看

适合不知道这个文件夹下面都装了些啥时侯使用。

1

代码
activedir:=Explorer_GetPath(WinExist("A"))
Run %ComSpec% /c ""C:\miniapp\SpaceSniffer.exe" scan " %activedir%,,Hide

;以下是库
Explorer_GetPath(hwnd="")
{
    if !(window := Explorer_GetWindow(hwnd))
        return ErrorLevel := "ERROR"
    if (window="desktop")
        return A_Desktop
    path := window.LocationURL
    path := RegExReplace(path, "ftp://.*@","ftp://")
    path := RegExReplace(path, "%20"," ") ;替换空格,否则显示%20
    StringReplace, path, path, file:///
    StringReplace, path, path, /, \, All
    ; thanks to polyethene
    Loop
        If RegExMatch(path, "i)(?<=%)[da-f]{1,2}", hex)
            StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
        Else Break
    return path
}
 
Explorer_GetAll(hwnd="")
{
    return Explorer_Get(hwnd)
}
 
Explorer_GetSelected(hwnd="")
{
    return Explorer_Get(hwnd,true)
}
 
Explorer_GetWindow(hwnd="")
{
    ; thanks to jethrow for some pointers here
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
 
    if (process!="explorer.exe")
        return
    if (class ~= "(Cabinet|Explore)WClass")
    {
        for window in ComObjCreate("Shell.Application").Windows
            if (window.hwnd==hwnd)
                return window
    }
    else if (class ~= "Progman|WorkerW")
        return "desktop" ; desktop found
}
 
Explorer_Get(hwnd="",selection=false)
{
    if !(window := Explorer_GetWindow(hwnd))
        return ErrorLevel := "ERROR"
    if (window="desktop")
    {
        ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
        if !hwWindow ; #D mode
            ControlGet, hwWindow, HWND,, SysListView321, A
        ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
        base := SubStr(A_Desktop,0,1)=="" ? SubStr(A_Desktop,1,-1) : A_Desktop
        Loop, Parse, files, `n, `r
        {
            path := base "" A_LoopField
            IfExist %path% ; ignore special icons like Computer (at least for now)
                ret .= path "`n"
        }
    }
    else
    {
        if selection
            collection := window.document.SelectedItems
        else
            collection := window.document.Folder.Items
        for item in collection
            ret .= item.path "`n"
    }
    return Trim(ret,"`n")
}

2. 文件移动专家

更便捷(最便捷?)地移动文件。

1

image

代码
#Requires AutoHotkey v2.0
#SingleInstance Force
global allcopyed

;获取当前文件的两重父文件夹
{
activedir:=Explorer_GetPath()
SplitPath activedir , , &activedirpapa
SplitPath activedirpapa , , &activediryaya
}

;获取选中的文件、文件夹列表
{
A_Clipboard:=""
sendinput "^c"
allcopyed:=""
ClipWait(0.2)
ClipSaved := ClipboardAll()
A_Clipboard := ClipSaved 
ClipSaved := ""
allcopyed:=A_Clipboard
A_Clipboard:=""
;msgbox(allcopyed activedir activedirpapa activediryaya)
}

{
	global WinID := WinExist("A")
	ContextMenu := Menu()

	{
		ContextMenu.Add(activediryaya, MenuHandler)	;如要添加自定义路径,可复制本行和下一行,只修改其中路径即可
		ContextMenu.SetIcon(activediryaya, "shell32.dll", 147)
		ContextMenu.Add(activedirpapa, MenuHandler)	;如要添加自定义路径,可复制本行和下一行,只修改其中路径即可
		ContextMenu.SetIcon(activedirpapa, "shell32.dll", 147)
		ContextMenu.Add
	}

	;---------------资源管理器-------------------------
	For openedwindows in ComObject("shell.Application").windows
	{
		This := openedwindows.Document.Folder.Self.Path
		ContextMenu.Add(This, MenuHandler)
		ContextMenu.SetIcon(This, "shell32.dll", 5)
	}
	openedwindows := ""	;清空变量

	;---------------Total Commander-------------------
	if WinExist("ahk_class TTOTAL_CMD")
	{
		TCPath := WinGetProcessPath("ahk_class TTOTAL_CMD")
		cm_CopySrcPathToClip := 2029	;Total Commander 内部代码
		cm_CopyTrgPathToClip := 2030
		ClipSaved := ClipboardAll()
		A_Clipboard := ""

		SendMessage(1075, cm_CopySrcPathToClip, 0, , "ahk_class TTOTAL_CMD")
		ContextMenu.Add
		ContextMenu.Add(A_Clipboard, MenuHandler)
		ContextMenu.SetIcon(A_Clipboard, TCPath, 1)

		SendMessage(1075, cm_CopyTrgPathToClip, 0, , "ahk_class TTOTAL_CMD")
		ContextMenu.Add(A_Clipboard, MenuHandler)
		ContextMenu.SetIcon(A_Clipboard, TCPath, 1)

		A_Clipboard := ClipSaved
		ClipSaved := ""
	}
	;--------------常用文件夹-------
	ContextMenu.Add
	ContextMenu.Add("常用路径", MenuHandler)
	ContextMenu.Disable("常用路径")
	ContextMenu.Add("C:\miniapp", MenuHandler)	;如要添加自定义路径,可复制本行和下一行,只修改其中路径即可
	ContextMenu.SetIcon("C:\miniapp", "shell32.dll", 44)
	
	ContextMenu.Add("G:\代码库\自写软件\clauch增强\ahks", MenuHandler)	
	ContextMenu.SetIcon("G:\代码库\自写软件\clauch增强\ahks", "shell32.dll", 44)
	
	;ContextMenu.Add("%UserProfile%\", MenuHandler)	;用户文件夹
	;ContextMenu.SetIcon("%UserProfile%\", "shell32.dll", 44)
	;------------------------------
	ContextMenu.Show
	ContextMenu.Delete
} 

#HotIf	;关闭上下文相关性

MenuHandler(ItemName, ItemPos, MyMenu)
{
	global allcopyed
	WinActivate "ahk_id" WinID

errorfind:=0

	if allcopyed
{
	Loop parse, allcopyed, "`n", "`r"
{
	try
  {
	;msgbox A_LoopField
	if ! DirExist(A_LoopField)
	FileMove A_LoopField, ItemName , 0
	else
	{
		SplitPath A_LoopField , &OutFileName
		DirMove A_LoopField, ItemName "\" OutFileName, 0
	}
	}
	catch
		errorfind++
}
if errorfind
	msgbox errorfind "个文件未成功移动,大概是因为有重复文件"
}
	else
{
	try
	{
		if ControlGetEnabled("ToolbarWindow323", WinID) = 1 or ControlGetEnabled("ToolWindow324", WinID) = 1
		{
			Send "!d"
			Sleep 100	;等待获取焦点,如果设为 50 ,在 chrome 中另存为会出现焦点错误
			addressbar := ControlGetFocus("A")	; 按下 alt+D 之后的焦点为地址栏
			ControlSetText(ItemName, addressbar, "A")
			ControlSend("{Enter}", addressbar, "A")
			ControlFocus("Edit1", "A")	;焦点移回到 Edit1
		}
	}
	catch TargetError
	{
		FolderPath := ItemName
		OldText := ControlGetText("Edit1", "A")	;读取当前 Edit1 控件中的文件名
		ControlFocus "Edit1", "A"

		Loop 5
		{
			ControlSetText FolderPath, "Edit1", "ahk_id" WinID
			Sleep(50)
			CurControlText := ControlGetText("Edit1", "ahk_id" WinID)
			if (CurControlText = FolderPath)
				break
		}

		Sleep 50
		ControlSend "{Enter}", "Edit1", "A"
		Sleep 50

		If !OldText	;插入原始文件名
			return

		Loop 5
		{
			ControlSetText OldText, "Edit1", "A"
			Sleep 50
			CurControlText := ControlGetText("Edit1", "A")
			if (CurControlText = OldText)
				break
		}
	}
}
}

Explorer_GetPath() {
   winClass := WinGetClass(hWnd := WinExist("A"))
   if !(winClass ~= "(Cabinet|Explore)WClass")
      return
   for window in ComObject("Shell.Application").Windows
      if (hWnd = window.hWnd)
         return window.Document.Folder.Self.Path
}
4 个赞