← Back to Blog

Boost Efficiency: AutoHotkey Solution for Quick Video File Access

Boost Efficiency: AutoHotkey Solution for Quick Video File Access Here's an updated AutoHotkey script that will open the specified folder, find the latest .mp4 file, and move the mouse to it, ready to drag: Create the Script : Open a text editor (like Notepad).

Boost Efficiency: AutoHotkey Solution for Quick Video File Access

Here's an updated AutoHotkey script that will open the specified folder, find the latest .mp4 file, and move the mouse to it, ready to drag:

  • Create the Script:

  • Open a text editor (like Notepad).

  • Copy and paste the following script into the editor.

  • Save the file with an .ahk extension, for example, SelectLatestMP4.ahk.

NoEnv

SendMode Input
SetWorkingDir %A_ScriptDir%

; Specify the folder to search
folderPath := "C:\Users\rifat\Videos"

latestFile := ""
latestTime := 0

Loop, Files, %folderPath%*.mp4, FR
{
fileTime := A_LoopFileTimeCreated
; Convert the file creation time to seconds since the epoch
fileTime := StrReplace(fileTime, ":", "", A_LoopFileName)
fileTime := StrReplace(fileTime, " ", "", A_LoopFileName)
if (fileTime > latestTime)
{
latestTime := fileTime
latestFile := A_LoopFileFullPath
}
}

if (latestFile != "")
{
; Open the folder in File Explorer
Run, % "explorer.exe /select," latestFile

; Wait for the Explorer window to open and stabilize
                WinWaitActive, ahk_class CabinetWClass, , 3
                Sleep, 1000
                
                ; Find the latest file in the Explorer window and select it
                ControlFocus, DirectUIHWND1, ahk_class CabinetWClass
                ControlSend, DirectUIHWND1, ^f, ahk_class CabinetWClass
                Sleep, 500
                Send, % latestFile
                Sleep, 500
                Send, {Enter}
                Sleep, 1000
                
                ; Ensure the file is selected
                Send, {Up}
                Sleep, 100
                Send, {Down}
                Sleep, 100
                
                ; Move the mouse to the selected file and click it to ensure it's ready to drag
                CoordMode, Mouse, Screen
                MouseMove, 100, 100 ; Arbitrary starting point to ensure mouse movement starts
                MouseClick, left
                MouseMove, 100, 100, 0 ; Move to the initial position
                ControlGetPos, x, y, w, h, DirectUIHWND1, A ; Get the position of the Explorer window
                MouseMove, x + 50, y + 150, 0 ; Move the mouse to the general area of the file (adjust as needed)
                MouseClick, left, x + 50, y + 150, 1, 0 ; Click to select the file (adjust as needed)
                

}
else
{
MsgBox, No .mp4 files found in the specified folder.
}

  • Customize Mouse Position:

  • The MouseMove and MouseClick commands may need to be adjusted based on your screen resolution and the exact layout of the File Explorer window. The script moves the mouse to a position relative to the Explorer window; you may need to tweak these values to ensure the correct file is selected.

  • Run the Script:

  • Double-click the .ahk file to run the script.

  • The script will open the C:\Users\rifat\Videos folder in File Explorer, find the latest .mp4 file, select it, and move the mouse to it, ready for dragging.

This script assumes a standard layout of File Explorer and may need adjustments based on your specific setup. The MouseMove and MouseClick positions might need fine-tuning to ensure the mouse accurately selects the latest file.

https://github.com/rifaterdemsahin/videoedittors/blob/main/mouseselectlastvideo.ahk


Imported from rifaterdemsahin.com · 2024