Script to click and rename a file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Martini2000
Posts: 1
Joined: 16 Aug 2022, 04:43

Script to click and rename a file

Post by Martini2000 » 16 Aug 2022, 04:48

Hello, there! >OBI WAN KENOBI<

I need to copy paste, a lot of names of videdo files from windows. I have lots of videos and I have to copy their names.
I want to create a script which will MOUSE CLICK + RENAME the file so I can use CTRL+C and copy the name directly, without moving my mouse lots of time.

Do you have any idea, how could I do such a script?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Script to click and rename a file

Post by BoBo » 16 Aug 2022, 05:44

Welcome to this Autohotkey forum.

Code: Select all

F12::					;press F12
	path := "C:\myDir\mySubDir\*.mp4"
	Loop, Files,% path
		clipboard .= A_LoopFileName "`n"
	MsgBox % clipboard
return
OTOH, you simply can use Explorers "Copy As Path..."-context menu option :yawn:
https://www.tenforums.com/tutorials/131557-copy-path-file-explorer-windows-10-a.html

zuzu_kuc
Posts: 76
Joined: 30 Mar 2016, 12:36

Re: Script to click and rename a file

Post by zuzu_kuc » 16 Aug 2022, 06:00

You can use Total Commander
just select menu MARK / copy file name OR copy filename with path.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Script to click and rename a file

Post by wetware05 » 16 Aug 2022, 06:47

I think your requirement is not clear. One by one? The following script copies the name of the file that is under the cursor, to the clipboard, with the typical combination of Crontrol+c.

It makes use of the ACC.ahk library, but the necessary function is built in at the bottom of the script.

Code: Select all

;^F3::
~^C::
TrayTip
FullPath:=Explorer_GetSelection()
;FullPath:=Explorer_GetActiveFolderPath()
MouseGetPos, x1, y1, WinUMID
WinGetClass, WinClass, A
Clipboard:=""

if Not (WinClass = "CabinetWClass" or WinClass = "Progman")
;if Not (WinClass = CabinetWClass or WinClass = Progman)
 {
 Return
 }

oAcc := Acc_ObjectFromPoint(vChildID)
;vChildID := 0 ;for a slightly different result uncomment this line
vText1 := vText2 := ""
try vText1 := oAcc.accName(vChildID) ;get text
try vText2 := oAcc.accValue(vChildID) ;get value
if !(vText1 = "")
	Clipboard .= "`r`n" vText1
/*
if !(vText2 = "") && !(vText = vText2)
	Clipboard .= "`r`n" vText2
*/
oAcc := ""

TrayTip, Filename:, %Clipboard%,, 0x1, 0x10, 0x20
Return

;------------------------------

Explorer_GetSelection() {
   WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
   if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
      Return
   
   shellWindows := ComObjCreate("Shell.Application").Windows
   if (winClass ~= "Progman|WorkerW")
      ;shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
      shellFolderView := shellWindows.Item( ComObject(VT_UI4 := 0x13, SWC_DESKTOP := 0x8) ).Document
   else {
      for window in shellWindows
         if (hWnd = window.HWND) && (shellFolderView := window.Document)
            break
   }
   for item in shellFolderView.SelectedItems
      result .= (result = "" ? "" : "`n") . item.Path
   if !result
      result := shellFolderView.Folder.Self.Path
   Return result
}

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Script to click and rename a file

Post by BoBo » 16 Aug 2022, 06:59

Subject line: "Script to click and rename a file" … [to do finally this] … "I have lots of videos and I have to copy their names."
Indeed, a kinda confusing requirement setting. :lolno:

Post Reply

Return to “Ask for Help (v1)”