Find out files opened by an application Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Find out files opened by an application

Post by wetware05 » 23 Dec 2022, 09:34

Hi.

I have optimized the script, thanks to the help of mikeyww viewtopic.php?f=76&t=111854 and Void https://www.voidtools.com/forum/viewtopic.php? p=51625#p51625 and I have added more symbols that can hinder the search —when part of the file name is closed with () or []—.

In the preferences of the "Everything" program, activate the "Espand environment variables" box, in the "Search" section, as shown in the image.

Image

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory
;EnvSet, SD, %A_ScriptDir%

;^!F8:: ; If a keyboard shortcut is used, all lines with the "ExitApp" command must be replaced by the "Return" command, except the last line.
GetKeyState, state, Ctrl
if (state = "D") ; Hold down the "Ctrl" key if you want to clear the clipboard and pop up the search window.
{
 ClipBoard:=""
}

Send ^c ; You only need to select the search text.

OutFile = h:\File_Temp.txt ;Change the output file path if necessary. This file is not deleted until the next search.
App = d:\Utilidades\Everything\es.exe ;Change the path of the "Everything.exe" program if necessary.

DetectHiddenWindows, Off
if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

If !Clipboard
 {
 Gosub, SearchGUI
 }
Else
 {
 TempClip:= Clipboard
 Gosub, Rutine
 }
Return

SearchGUI:
TempClip:=Clipboard
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vMySearch, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, CheckBox, x10 y46 w300 h20 vRegEx, Use RegEx Search
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w330, GUI
Return

#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
Search:
Gui Search: Submit
TempClip:=MySearch
Gui Search: Destroy
Gosub, Rutine
Return

Rutine:
FileDelete, %OutFile%
If RegEx=1
 {
 RunWait, "%App%" -export-txt "%OutFile%" -r "%TempClip%",, Hide
 }
 Else
 {
 TempClip:= RegexReplace(TempClip, "[\[\]()\-\_\s+]", "*") ;Subtract or add symbols within this replacement line of the text to find. Now replace the symbols: -_[]() and space with a wildcard.
 RunWait, "%App%" -export-txt "%OutFile%" "%TempClip%",, Hide
 }
FileRead, OutputEnd, %OutFile%

If !OutputEnd
 {
 Gosub, NotFound
 }
Else
 {
 Gosub, GuiControl
 }
Return
 
GuiControl:
Loop, Read,  %OutFile%
NumLines := A_Index
SoundPlay, *64
xposControl:= Floor((A_ScreenWidth/2)-450)
yposControl:= Floor((A_ScreenHeight/2)-200)
Gui, Control: Add, GroupBox, x22 y60 w340 h140, Options
Gui, Control: Add, Radio, x32 y80 w300 h20 vDirectory, Open the Container Directory
Gui, Control: Add, Radio, x32 y100 w300 h20 vOpenFile,  Open the file
Gui, Control: Add, Radio, x32 y120 w300 h20 vFileAndDir, Open the File and Open the Directory
Gui, Control: Add, Radio, x32 y140 w300 h20 vNothing Checked, Do Nothing
Gui, Control: Add, CheckBox, x32 y170 w100 h20 vCopyClip, Copy to Clipboard
Gui, Control: Add, CheckBox, x150 y170 w100 h20 vTxtOpen, Open file List
Gui, Control: Add, Button, x30 y210 w100 h30 gCancel, Cancel
Gui, Control: Add, Button, x252 y210 w100 h30 gOptions, OK
Gui, Control: Add, Text, x22 y16 w340 h40 , %NumLines% file(s) exists in %OutputEnd%
Gui, Control: Show,x%xposControl% y%yposControl% h260 w384, GUI Control
Return

Options:
Gui, Control: Submit

If Directory
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
 {
 FileReadLine, VarOut, %OutFile%, %A_Index%
 StringGetPos, pos, VarOut, \, r1
 length := pos+1
 StringLeft, OutText, VarOut, %length%
 Run, explorer %OutText%
 }
 }
Else
 {
 StringGetPos, pos, OutputEnd, \, r1
 length := pos+1
 StringLeft, OutText, OutputEnd, %length%
 Run, explorer %OutText%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp
 }

If OpenFile
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
  {
  FileReadLine, VarOut, %OutFile%, %A_Index%
  Run, Explorer %VarOut%
  }
 }
Else
 {
 Run, Explorer %OutputEnd%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp
 }
  
If FileAndDir
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
  {
  FileReadLine, VarOut, %OutFile%, %A_Index%
  Run, Explorer %VarOut%
  StringGetPos, pos, VarOut, \, r1
  length := pos+1
  StringLeft, OutText, VarOut, %length%
  Run, Explorer %OutText%
  }
  }
Else
 {
 Run, Explorer %OutputEnd%
 StringGetPos, pos, OutputEnd, \, r1
 length := pos+1
 StringLeft, OutText, OutputEnd, %length%
 Run, explorer %OutText%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp
 }

If Nothing
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp

NotFound:
SoundPlay, *64
MsgBox, The file does not exist on the computer.
ExitApp

Cancel:
ExitApp
Oh, sorry for the big images. It is because of the 4K monitor, I would have to reduce them.

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

Re: Find out files opened by an application

Post by wetware05 » 26 Dec 2022, 16:15

Hi.

The fruit of a script created by mikeyww (viewtopic.php?f=76&t=111978) and another series of "discoveries" of how the "Everything" search engine works, the following script is an improvement on one of the above.

The script consists of "viewing" all open instances of PotPlayer (it can be used for another program), searching for its title and using "everything" creating a list of open files (videos, in this case) with the full path. (I extract portions of "neutral" videos that can be used to make montages —people walking down the street, a landscape, a plane flying...— to later use it in video montages; I watch several at the same time to optimize the time, so I need to know what videos you had open in the previous session).

What improvements does it have? In the previous one, each title was saved in a file, which later had to be read, to search in Everythig and create the final file. At first I thought of creating an array —hence the mikeyww script utility—, to "dump" all the content at the end to a file (lines that are now commented out, after a semicolon; I have left those two lines by if other people want to take note about the process to create an array of the instances of an open program), but later I realized that it was not necessary, ssince with each Loop I can record the search results and thus avoid creating a second loop to "dump" the array to a text file.

Code: Select all

DetectHiddenWindows, On
;arr := []

Iniciate := 0
loop, h:\PlayList\PlayerList_*.m3u
Iniciate := % Floor(A_Index)

if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

Iniciate++
WinGet, Hwnds, List, ahk_class PotPlayer64
Loop, % Hwnds {
    WinGetTitle, ThisTitle, % "ahk_id " Hwnds%A_Index%
    OutputVar:= StrReplace(ThisTitle, " - PotPlayer")
    runwait, %comspec% /c chcp 65001 & d:\Utilidades\Everything\es.exe %OutputVar% | clip,, hide
    ;arr.Push(Clipboard)
    PlayerList:= "h:\PlayList\PlayerList_" Iniciate ".m3u"
    
    If !Clipboard
    {
    return
    }
  Else
    { 
    FileAppend, %Clipboard%, %PlayerList%
    ;FileAppend, % arr[A_Index], %PlayerList%
    }
}

;SoundPlay, *64
MsgBox 64, List creation, Ended process! 
Return
(I don't know programming, nor its jargon, but I manage ;) ).

---------

(I think you have to put some "sleep", because the process seems to go too fast and sometimes it gives errors.)

User avatar
andymbody
Posts: 957
Joined: 02 Jul 2017, 23:47

Re: Find out files opened by an application

Post by andymbody » 26 Dec 2022, 21:00

@wetware05

Thanks for posting your progress... I'm going to be digging into the Everything engine soon, and can use the pointers.

Andy

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

Re: Find out files opened by an application

Post by wetware05 » 01 Jan 2023, 15:35

Hi. :wave:

In this post, above all, I share the video for anyone who wants to know different tools, tools and programs that make use of the Everythig search engine (not all, but the most interesting).



By the way I have changed the main script that I am developing. I have added the ability to search only multimedia files (it is activated by holding down the "Alt" key, I'm developing it for my use, so I do not search for the most visual methods, but rather fast ones), and to be able to play them. I'm not done making the changes. Problem?, too many disjunctives arise (hence the cumbersome script now, full of conditionals -if- and "else"). I use it for videos, and I know that at most there is only one, so under these rules the script works. It is not intended for music, because if it finds multiple songs or tracks, with a similar name, it will open multiple instances of a player. What it should do is generate a playlist (I'll do it these days).

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory
;EnvSet, SD, %A_ScriptDir%

Multimedia=0
;^!F5:: ; If a keyboard shortcut is used, all lines with the "ExitApp" command must be replaced by the "Return" command, except the last line.
GetKeyState, state, Ctrl
if (state = "D") ; Hold down the "Ctrl" key if you want to clear the clipboard and pop up the search window.
{
 ClipBoard:=""
}

GetKeyState, state, Alt
if (state = "D") ; Hold down the "Ctrl" key if you want to clear the clipboard and pop up the search window.
{
Multimedia:=1
}

Send ^c ; You only need to select the search text.

OutFile = h:\File_Temp.txt ;Change the output file path if necessary. This file is not deleted until the next search.
OutMedia = h:\Temp_Media.txt
App = d:\Utilidades\Everything\es.exe ;Change the path of the "Everything.exe" program if necessary.

DetectHiddenWindows, Off
if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

If !Clipboard
 {
 Gosub, SearchGUI
 }
Else
 {
 TempClip:= Clipboard
 Gosub, Rutine
 }
Return

SearchGUI:
TempClip:=Clipboard
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vMySearch, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, CheckBox, x10 y46 w130 h20 vRegEx, RegEx Search
Gui, Search: Add, CheckBox, x140 y46 w100 h20 vMedia, Multimedia
Gui, Search: Add, Button, x250 y46 w65 h20 gCancel, Cancel
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w330, Search
Return

#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
Search:
Gui Search: Submit
TempClip:=MySearch
Gui Search: Destroy
Gosub, Rutine
Return

Rutine:
FileDelete, %OutFile%
FileDelete, h:\File_Temp_Full.txt
FileDelete, h:\Temp_Media_Full.txt
If RegEx=1
 {
 RunWait, "%App%" -export-txt "%OutFile%" -r "%TempClip%",, Hide
 }
 Else
 {
 TempClip:= RegexReplace(TempClip, "[\[\]()\-\_\s+]", "*") ;Subtract or add symbols within this replacement line of the text to find. Now replace the symbols: -_[]() and space with a wildcard.
 RunWait, "%App%" -export-txt "%OutFile%" "%TempClip%",, Hide
 }

If Media=1
 {
 Multimedia=1
 }
 
If Multimedia=1
 {
 FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(jpg|jpeg|png|gif|svg|tif|bmp|tga|psd|mp4|mkv|avi|ts|mov|mpeg|m4v|mp3|wav|ogg|flac|m4a|aif|aac)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\File_Temp_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
 }
FileDelete, %OutMedia%
FileRead, OutputEnd, %OutFile%

If !OutputEnd
 {
 Gosub, NotFound
 }
Else
 {
 Gosub, GuiControl
 }
Return
 
GuiControl:
Loop, Read,  %OutFile%
NumLines := A_Index
;SoundPlay, *64
xposControl:= Floor((A_ScreenWidth/2)-450)
yposControl:= Floor((A_ScreenHeight/2)-200)
Gui, Control: Add, GroupBox, x22 y60 w340 h140, Options
Gui, Control: Add, Radio, x32 y80 w300 h20 vDirectory, Open Container Directory
Gui, Control: Add, Radio, x32 y100 w80 h20 vOpenFile,  Open File
Gui, Control: Add, Radio, x32 y120 w300 h20 vFileAndDir, Open File and Open Directory
Gui, Control: Add, Radio, x32 y140 w300 h20 vNothing Checked, Do Nothing
Gui, Control: Add, CheckBox, x120 y100 w50 h20 vVideo, Video
Gui, Control: Add, CheckBox, x170 y100 w50 h20 vAudio, Audio
Gui, Control: Add, CheckBox, x220 y100 w50 h20 vImage, Image
Gui, Control: Add, CheckBox, x32 y170 w100 h20 vCopyClip, Copy to Clipboard
Gui, Control: Add, CheckBox, x150 y170 w100 h20 vTxtOpen, Open file List
Gui, Control: Add, Button, x30 y210 w100 h30 gCancel, Cancel
Gui, Control: Add, Button, x252 y210 w100 h30 gOptions, OK
Gui, Control: Add, Text, x22 y16 w340 h40, %NumLines% file(s) exists in %OutputEnd%
Gui, Control: Show,x%xposControl% y%yposControl% h260 w384, Coltrol
Return

Options:
Gui, Control: Submit

If Directory
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
 {
 FileReadLine, VarOut, %OutFile%, %A_Index%
 StringGetPos, pos, VarOut, \, r1
 length := pos+1
 StringLeft, OutText, VarOut, %length%
 Run, explorer %OutText%
 }
 }
Else
 {
 StringGetPos, pos, OutputEnd, \, r1
 length := pos+1
 StringLeft, OutText, OutputEnd, %length%
 Run, explorer %OutText%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp
 }

If OpenFile
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
  {
  If Video=1
   {
   Gosub, Video
   }
  If Audio=1
   {
   Gosub, Audio
   }
 If Image=1
   {
   Gosub, Image
   }
  
  Loop, Read,  %OutFile%
  NumLines1:= A_Index
  
 If (NumLines1<>1)
  {
 Loop, %OutFile%
 {
 FileReadLine, VarOut, %OutFile%, %A_Index%
 ;Run, %VarOut%
 Run, Explorer %VarOut%
 If A_Index=NumLines1
  {
  Break, 1
  }
 }
  }
 Else
  {
  FileRead, VarOut, %OutFile%
  Run, Explorer %VarOut%
  Break, 1
  }
 }
}
Else
 {
 Run, Explorer %OutputEnd%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp
 }
  
If FileAndDir
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
  {
  FileReadLine, VarOut, %OutFile%, %A_Index%
  Run, Explorer %VarOut%
  StringGetPos, pos, VarOut, \, r1
  length := pos+1
  StringLeft, OutText, VarOut, %length%
  Run, Explorer %OutText%
  }
  }
Else
 {
 Run, Explorer %OutputEnd%
 StringGetPos, pos, OutputEnd, \, r1
 length := pos+1
 StringLeft, OutText, OutputEnd, %length%
 Run, explorer %OutText%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp
 }

If Nothing
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Run, %OutFile%
  }
 ExitApp

NotFound:
;SoundPlay, *64
MsgBox 64, Not Exist, The file does not exist on the computer.
ExitApp

Cancel:
ExitApp

Video:
FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(mp4|mkv|avi|ts|mov|mpeg|m4v)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\Temp_Media_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
Return

Audio:
FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(mp3|wav|ogg|flac|m4a|aif|aac)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\Temp_Media_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
Return

Image:
FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(jpg|jpeg|png|gif|svg|tif|bmp|tga|psd)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\Temp_Media_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
Return
Small script code that restores all PotPlayer windows:

Code: Select all

WinGet, ff, List, ahk_exe PotPlayerMini64.exe
Loop, % ff 
WinActivate, % WinTitle := "ahk_id" ff%A_Index%
;ExitApp
(reissued. I got confused by linking the little script (I put one on which I was testing). changed.)

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

Re: Find out files opened by an application

Post by wetware05 » 06 Jan 2023, 15:14

Hi.

I have improved this little utility thanks to @flyingDman and the great script shared on this page viewtopic.php?f=76&t=103721. At the end of the search and if the "Open File List" option is chosen, a "listview" type gui will appear with the files found, where clicking on them will open them.

(I had planned to create this function, but they gave it to me... :dance: The next step is that a thumbnail appears, on the right, when hovering over each file.)

In the video below you can see how by holding down the Ctrl key (as opposed to not doing it, which will search for what the clipboard contains), a small window will appear to search, being able to select to only show us the multimedia files.


Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory
;EnvSet, SD, %A_ScriptDir%

Multimedia=0
;^!F5:: ; If a keyboard shortcut is used, all lines with the "ExitApp" command must be replaced by the "Return" command, except the last line.
GetKeyState, state, Ctrl
if (state = "D") ; Hold down the "Ctrl" key if you want to clear the clipboard and pop up the search window.
{
 ClipBoard:=""
}

GetKeyState, state, Alt
if (state = "D") ; Hold down the "Ctrl" key if you want to clear the clipboard and pop up the search window.
{
Multimedia:=1
}

Send ^c ; You only need to select the search text.

OutFile = h:\File_Temp.txt ;Change the output file path if necessary. This file is not deleted until the next search.
OutMedia = h:\Temp_Media.txt
App = d:\Utilidades\Everything\es.exe ;Change the path of the "Everything.exe" program if necessary.

DetectHiddenWindows, Off
if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

If !Clipboard
 {
 Gosub, SearchGUI
 }
Else
 {
 TempClip:= Clipboard
 Gosub, Rutine
 }
Return

SearchGUI:
TempClip:=Clipboard
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID	
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vMySearch, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, CheckBox, x10 y46 w130 h20 vRegEx, RegEx Search
Gui, Search: Add, CheckBox, x140 y46 w100 h20 vMedia, Multimedia
Gui, Search: Add, Button, x250 y46 w65 h20 gCancel, Cancel
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w330, Search
Return

#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
Search:
Gui Search: Submit
TempClip:=MySearch
Gui Search: Destroy
Gosub, Rutine
Return

Rutine:
ResvClip:=TempClip
FileDelete, %OutFile%
FileDelete, h:\File_Temp_Full.txt
FileDelete, h:\Temp_Media_Full.txt
If RegEx=1
 {
 RunWait, "%App%" -export-txt "%OutFile%" -r "%TempClip%",, Hide
 }
 Else
 {
 TempClip:= RegexReplace(TempClip, "[\[\]()\-\_\s+]", "*") ;Subtract or add symbols within this replacement line of the text to find. Now replace the symbols: -_[]() and space with a wildcard.
 RunWait, "%App%" -export-txt "%OutFile%" "%TempClip%",, Hide
 }

If Media=1
 {
 Multimedia=1
 }
 
If Multimedia=1
 {
 FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(jpg|jpeg|png|gif|svg|tif|bmp|tga|psd|mp4|mkv|avi|ts|mov|mpeg|m4v|mp3|wav|ogg|flac|m4a|aif|aac)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\File_Temp_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
 }
FileDelete, %OutMedia%
FileRead, OutputEnd, %OutFile%

If !OutputEnd
 {
 Gosub, NotFound
 }
Else
 {
 Gosub, GuiControl
 }
Return
 
GuiControl:
Loop, Read,  %OutFile%
NumLines := A_Index
;SoundPlay, *64
xposControl:= Floor((A_ScreenWidth/2)-450)
yposControl:= Floor((A_ScreenHeight/2)-200)
Gui, Control: Add, GroupBox, x22 y60 w340 h140, Options
Gui, Control: Add, Radio, x32 y80 w300 h20 vDirectory, Open Container Directory
Gui, Control: Add, Radio, x32 y100 w80 h20 vOpenFile,  Open File
Gui, Control: Add, Radio, x32 y120 w300 h20 vFileAndDir, Open File and Open Directory
Gui, Control: Add, Radio, x32 y140 w300 h20 vNothing Checked, Do Nothing
Gui, Control: Add, CheckBox, x120 y100 w50 h20 vVideo, Video
Gui, Control: Add, CheckBox, x170 y100 w50 h20 vAudio, Audio
Gui, Control: Add, CheckBox, x220 y100 w50 h20 vImage, Image
Gui, Control: Add, CheckBox, x32 y170 w100 h20 vCopyClip, Copy to Clipboard
Gui, Control: Add, CheckBox, x150 y170 w100 h20 vTxtOpen, Open File List
Gui, Control: Add, Button, x30 y210 w100 h30 gCancel, Cancel
Gui, Control: Add, Button, x252 y210 w100 h30 gOptions, OK
Gui, Control: Add, Text, x22 y16 w340 h40, %NumLines% file(s) exists in %OutputEnd%
Gui, Control: Show,x%xposControl% y%yposControl% h260 w384, Coltrol
Return

Options:
Gui, Control: Submit

If Directory
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
 {
 FileReadLine, VarOut, %OutFile%, %A_Index%
 StringGetPos, pos, VarOut, \, r1
 length := pos+1
 StringLeft, OutText, VarOut, %length%
 Run, explorer %OutText%
 }
 }
Else
 {
 StringGetPos, pos, OutputEnd, \, r1
 length := pos+1
 StringLeft, OutText, OutputEnd, %length%
 Run, explorer %OutText%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Gosub, ListCl
  ;Run, %OutFile%
  }
 ExitApp
 }

If OpenFile
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
  {
  If Video=1
   {
   Gosub, Video
   }
  If Audio=1
   {
   Gosub, Audio
   }
 If Image=1
   {
   Gosub, Image
   }
  
  Loop, Read,  %OutFile%
  NumLines1:= A_Index
  
 If (NumLines1<>1)
  {
 Loop, %OutFile%
 {
 FileReadLine, VarOut, %OutFile%, %A_Index%
 ;Run, %VarOut%
 Run, Explorer %VarOut%
 If A_Index=NumLines1
  {
  Break, 1
  }
 }
  }
 Else
  {
  FileRead, VarOut, %OutFile%
  Run, Explorer %VarOut%
  Break, 1
  }
 }
}
Else
 {
 Run, Explorer %OutputEnd%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Gosub, ListCl
  ;Run, %OutFile%
  }
 ExitApp
 }
  
If FileAndDir
 {
 If (NumLines<>1)
 {
 Loop, %NumLines%
  {
  FileReadLine, VarOut, %OutFile%, %A_Index%
  Run, Explorer %VarOut%
  StringGetPos, pos, VarOut, \, r1
  length := pos+1
  StringLeft, OutText, VarOut, %length%
  Run, Explorer %OutText%
  }
  }
Else
 {
 Run, Explorer %OutputEnd%
 StringGetPos, pos, OutputEnd, \, r1
 length := pos+1
 StringLeft, OutText, OutputEnd, %length%
 Run, explorer %OutText%
 }
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Gosub, ListCl
  ;Run, %OutFile%
  }
 ExitApp
 }

If Nothing
 If CopyClip=1
  {
  Clipboard:= OutputEnd
  }
 If TxtOpen=1
  {
  Gosub, ListCl
  ;Run, %OutFile%
  }
 Return
 ;ExitApp

NotFound:
;SoundPlay, *64
MsgBox 64, Not Exist, The file does not exist on the computer.
ExitApp

Cancel:
ExitApp

Video:
FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(mp4|mkv|avi|ts|mov|mpeg|m4v)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\Temp_Media_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
Return

Audio:
FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(mp3|wav|ogg|flac|m4a|aif|aac)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\Temp_Media_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
Return

Image:
FileDelete, %OutMedia%
 Loop, read, %OutFile%
 if RegExMatch(A_LoopReadLine, "\.(jpg|jpeg|png|gif|svg|tif|bmp|tga|psd)"$)
  {
  FileAppend, %A_LoopReadLine%`n, %OutMedia%
  FileCopy, %OutFile%, h:\Temp_Media_Full.txt
  FileCopy, %OutMedia%, %OutFile%, 1
  }
Return

ListCl:
;FileRead, vOutput, %OutFile%,
Gui, Control: Destroy
vOutput:=OutputEnd
gui, font, s12
;gui, margin, 0, 0
gui, margin, 5, 5
gui, -caption
;Gui, Font, S9 Bold, Verdana
gui, add, Text, w350 h20 GuiMove, %ResvClip% - Search Results
gui, add, listview, w400 r10 -hdr gMyLV, flnm|fllpth
gui, add, button, w0 h0 hidden default, Ok 
Gui, Font, S9, Verdana
gui, add, button, x372 y5 w50 h20 gClose, Close
for x,y in strsplit(vOutput,"`n", "`r")
	{
	splitpath,y,z	
	lv_add("",z,y)
	} until (x = 30) ; 30 Results
LV_ModifyCol(1,380)
LV_ModifyCol(2,0)
gui, show
return

MyLv:
LV_GetText(fllpth, A_EventInfo, 2) 
;gui, destroy
run, Explorer %fllpth%
return

ButtonOK:
LV_GetText(fllpth, LV_GetNext(0, "Focused"),2)
;gui, destroy
run, Explorer %fllpth%
return

~Esc::
Close:
gui, destroy
ExitApp

uiMove:
PostMessage, 0xA1, 2,,, A 
Return
(One of these days I have to review the script conceptually, since now its function and use is a bit confusing.)

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

Re: Find out files opened by an application

Post by wetware05 » 09 Apr 2023, 09:23

Hi, I am going to share here five small scripts that I have created (or made variations) regarding the use of Porplayer, file search, etc.

1. Simplified search to check if a media file already exists on the computer (requires the Everything command line utility, everything is explained above or in the videos).

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory
;EnvSet, SD, %A_ScriptDir%

;__________________________________________________________________________________________________________________________

#SingleInstance, Off

;__________________________________________________________________________________________________________________________

Multimedia=0
GetKeyState, state, Ctrl
if (state = "D")
{
 ClipBoard:=""
}

GetKeyState, state, Alt
if (state = "D")
{
TempClip:= Clipboard
 Gosub, Rutine
}

;__________________________________________________________________________________________________________________________

Send ^c

OutFile = h:\File_Temp.txt
OutMedia = h:\Temp_Media.txt
App = d:\Utilidades\Everything\es.exe

;__________________________________________________________________________________________________________________________

DetectHiddenWindows, Off
if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

;__________________________________________________________________________________________________________________________

If !Clipboard
 {
 Gosub, SearchGUI
 }
Else
 {
 TempClip:= Clipboard
 Gosub, Rutine
 }
Return

;__________________________________________________________________________________________________________________________

SearchGUI:
TempClip:=Clipboard
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID	
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vMySearch, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, CheckBox, x10 y46 w130 h20 vRegEx, RegEx Search
Gui, Search: Add, Button, x250 y46 w65 h20 gCancel, Cancel
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w330, Search
Return

#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
Search:
Gui Search: Submit
TempClip:=MySearch
Gui Search: Destroy
Gosub, Rutine
Return

;__________________________________________________________________________________________________________________________

Rutine:
ResvClip:=TempClip
FileDelete, %OutFile%
FileDelete, h:\File_Temp_Full.txt
FileDelete, h:\Temp_Media_Full.txt

If RegEx=1
 {
  RunWait, "%App%" -export-txt "%OutFile%" -r "%TempClip%",, Hide
 }
 Else
 {
  TempClip:= RegexReplace(TempClip, "[\[\]()\-\_\s+]", "*")
  RunWait, "%App%" -export-txt "%OutFile%" "%TempClip%",, Hide
 }

FileDelete, %OutMedia%
FileRead, OutputEnd, %OutFile%

If !OutputEnd
 {
 Gosub, NotFound
 }
Else
 {
 ;Gosub, GuiControl
 Gosub, ListCl
 }
Return

;__________________________________________________________________________________________________________________________

NotFound:
MsgBox, 262144, %Clipboard%, The file does not exist on the computer.
;Gosub, Replace
;ClipBoard:=TempClip
ExitApp

;__________________________________________________________________________________________________________________________

Cancel:
Gosub, Replace
ClipBoard:=TempClip
ExitApp

;__________________________________________________________________________________________________________________________

^F11::
ListCl:
Gui, Control: Destroy
vOutput:=OutputEnd
Gui, Font, s12
Gui, Margin, 5, 5
Gui, -Caption +AlwaysOnTop
Gui, Add, Text, w350 h20 GuiMove, %ResvClip% ; - Search Results
Gui, Add, Listview, w416 r10 -hdr gMyLV, flnm|fllpth
;Gui, Add, Listview, backgroundGray w416 r10 -hdr gMyLV, flnm|fllpth
Gui, Add, Button, w0 h0 hidden default, Ok 
Gui, Font, S9, Verdana
Gui, Add, Button, x326 y5 w70 h20 gCopyClip, ClipBoard
Gui, Font, S10, Verdana Bold
Gui, Add, Button, x400 y5 w20 h20 gClose, X
for x,y in strsplit(vOutput,"`n", "`r")
	{
	splitpath,y,z	
	lv_Add("",z,y)
	} until (x = 30) ; 30 Results
LV_ModifyCol(1,380)
LV_ModifyCol(2,0)
Gui, Show
Return

;__________________________________________________________________________________________________________________________

CopyClip:
Gosub, Replace
Clipboard:= OutputEnd
Return

;__________________________________________________________________________________________________________________________

MyLv:
LV_GetText(fllpth, A_EventInfo, 2) 
run, Explorer %fllpth%
Return

;__________________________________________________________________________________________________________________________

ButtonOK:
LV_GetText(fllpth, LV_GetNext(0, "Focused"),2)
run, Explorer %fllpth%
Return

;__________________________________________________________________________________________________________________________

~Esc::
Close:
Gui, Destroy
Gui, Search: Destroy
Gosub, Replace
ClipBoard:=TempClip
ExitApp

GuiClose:
Gosub, Replace
ClipBoard:=TempClip
ExitApp

;__________________________________________________________________________________________________________________________

uiMove:
PostMessage, 0xA1, 2,,, A 
Return

;__________________________________________________________________________________________________________________________

Replace:
TempClip:=RegexReplace(TempClip, "\*", "-")
Return
A variation is to add this little script segment at the beginning, in case you want to do an OCR with the free "PowerToys" utility, as sometimes it's not easy to copy the title from by selecting and sending Ctrl+ c.

Code: Select all

Clipboard:=""
Send +#t
ClipWait,10,1
Sleep,1200
2. Copy the name of all the videos open in the different instances of PotPlayer. It simply calls (via a keyboard shortcut to be configured in PotPlayer) the ability to copy the name of the open file to the clipboard. The script is created to copy all titles to open instances of PotPlayer.

Code: Select all

DetectHiddenWindows, On

Iniciate:= 0
loop, h:\PlayList\PlayerList_*.m3u
Iniciate := % Floor(A_Index)+1
PlayerList:= "h:\PlayList\PlayerList_" Iniciate ".m3u"

;ListTemp:= "h:\PlayList\PlayerList_" Iniciate ".txt"

WinGet, Hwnds, List, ahk_class PotPlayer64
Loop, % Hwnds {
    WinGetTitle, winTitle, % "ahk_id " Hwnds%A_Index%
    WinGet, PID, PID, % winTitle
    WinGetTitle, title, % winTitle
    WinActivate, % winTitle

    Send, ^!{F8}

    Sleep, 100

    FileAppend, %ClipBoard%`n, %PlayerList%
    }

SoundPlay, *64
MsgBox, ¡Proceso Finalizado!
(Change the keyboard shortcut of the line 17 if necessary)

Image

3. Creates a random list of X songs by searching the directories that contain the file "Full_Directory.txt". In my case, for simplicity, I convert everything to .mp3, if you have other extensions you have to add them to the script. The script creates a complete list of directories and then creates a list of X songs. If there are not many changes to the directories, keep the entire file (it is deleted each time the script runs, to update it) and create the list from that list.

Code: Select all

FileDelete, Full_Mp3.txt

loop, h:\PlayList\Listas Generadas\NewList_*.m3u
Iniciate := % Floor(A_Index)+1

Loop, Read, Full_Directory.txt
NumDirectory:= % Floor(A_Index)

PlayerList:= "h:\PlayList\Listas Generadas\NewList_" Iniciate ".m3u"

Number:=""

InputBox, Number, Number of Videos in the List, , , 250, 100

Loop, %NumDirectory%
{
FileList := ""
FileReadLine, NameFile, Full_Directory.txt, %A_Index%
NameFileTemp:= NameFile "\*.mp3"
Loop, Files, %NameFileTemp%, R
FileList .= A_LoopFileFullPath "`n"
FileAppend, %FileList%, Full_Mp3.txt
}

Loop, Read,  Full_MP3.txt
NumLines := A_Index

Loop, %Number%
{
NumList:= UniqueRands( 1, NumLines, 25 )
FileReadLine, NameFile, Full_Mp3.txt, %NumList%
FileAppend, %NameFile%`n, %PlayerList%
}

FileDelete, Full_Mp3.txt

SoundPlay, *64
MsgBox, ¡Proceso Finalizado!

UniqueRands( Low, High, HowMany=1 ) ; integers only
{
   If (Low > High)
      return UniqueRands( High, Low, HowMany )
   If ( HowMany > 1 && Howmany - 1 <= High - Low )
   {
      Nums := Low
      Loop % High - Low
         Nums .= "`n" Low + A_Index
      Sort, Nums, Random
      Pos := 0
      Loop %HowMany%
         Pos := InStr( Nums "`n", "`n", 0, Pos+1 )
      return SubStr( Nums "`n", 1, Pos-1 )
   }
   Random, Nums, %Low%, %High%
   return Nums
}
Sample list "Full_Directory.txt":

Code: Select all

h:\Mp3\
f:\Temporal\MP3\
i:\Foundry\Mp3\
l:\Download\Varios archivos\
h:\MP3\Download_DL\
4. I download a lot of songs to a single directory, and then I sort them into folders and drives. The problem with this approach is that in the end I forget what I have downloaded in the last few days. This script creates a list of new songs from the last X days.

Code: Select all

OutFile = h:\Temp_Files.m3u

FileDelete, %OutFile%

InputBox, Number, Number of Days to Search, , , 250, 100

Loop, Read, Full_Directory.txt
NumDirectory:= % Floor(A_Index)
NoWBack:= SubStr(A_Now, 1, 8)-Number

Loop, %NumDirectory%
{
FileReadLine, NameFile, Full_Directory.txt, %A_Index%
ttext := "", n := 0
Loop, Files, %NameFile%*.mp4, R
If SubStr(A_LoopFileTimeCreated, 1, 8) >= NoWBack
ttext .= A_LoopFileFullPath "`n", n++

NameSave:= % SubStr(ttext, 2)
FileAppend, %NameSave%, %OutFile%
}
5. This script is a bit "exotic". If you understand what it does, it's easy to know what it can be used for (to a good understanding, few words are worth it). Having multiple instances of PotPlayer, this script periodically activates one of the windows, maximizes it, and plays it. After X time for reproduction (the line 17 changes the time in reproduction) and restores the window to recreate the same process with the next window. Both hands are free. ;)

Code: Select all

DetectHiddenWindows, On

^F5::
WinGet, Hwnds, List, ahk_class PotPlayer64
Loop, % Hwnds {
    WinGetTitle, winTitle, % "ahk_id " Hwnds%A_Index%
    WinGet, PID, PID, % winTitle
    WinGetTitle, title, % winTitle
    WinActivate, % winTitle
    Sleep, 300

    WinGetActiveStats, Title1, Width, Height, X, Y
    MouseMove, Width / 2, Height / 2, 0
    Click, 2
    Sendinput, {Space}
    
    Sleep, 10000
    Sendinput, {Space}
    Click, 2 
 }

Return

^p::Pause,Toggle
Ctrl+P toggles between pausing and unpausing, in case you want to keep one of the playbacks longer. (I do not remember well. PotPlayer may need to be configured to stop playback when it loses focus. No, the pause key does it.).

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

Re: Find out files opened by an application

Post by wetware05 » 13 Apr 2023, 14:44

Hi.

Helped by NotNull from the EveryThing search engine forum (https://www.voidtools.com/forum/viewtopic.php?p=55780#p55780)a script to search for new files with an extension from the last X days in different directories.

Code: Select all

OutFile = h:\LastFiles_MP3.txt
App = d:\Utilidades\Everything\es.exe

RunWait,  %comspec% /c chcp 65001 & "%App%" dm:last1days ext:mp3 I:\Temp\Foundry ^| M:\Temp ^| h:\Temp\01 ^| F:\Temp\ -export-txt "%OutFile%",, Hide
Number in code last1days determines the number of days, evident!

Chain multiple types of extensions: ext:mp3 ^| jpg ^| mp4

(This post follows the current thread, where the es.exe file is used for the command line of the Eveything search).

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

Re: Find out files opened by an application

Post by wetware05 » 14 Apr 2023, 09:13

Hi. :thumbup:

More complete version of the previous script. I forgot to include the routine that starts "Everything.exe", because if it is not started the script does not work.

I have added a GUI to enter hours or days.

Code: Select all

DetectHiddenWindows, Off
OutFile = h:\LastFiles_MP3.m3u
App = d:\Utilidades\Everything\es.exe

if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

FileDelete, %OutFile%

SearchGUI:
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID	
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vNumber, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, Radio, x10 y46 w120 h20 vHours, Hours Search
Gui, Search: Add, Radio, x130 y46 w120 h20 Checked vDays, Days Search
Gui, Search: Add, Button, x250 y46 w65 h20 gCancel, Cancel
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w330, Search
Return

#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::

Search:
Gui Search: Submit
If Hours=1
{
TimeS:= "last" Number "hours"
}

If Days=1
{
TimeS:= "last" Number "days"
}
Gui Search: Destroy

RunWait,  %comspec% /c chcp 65001 & "%App%" dm:"%TimeS%" ext:mp3 G:\Download\Mp3 ^| I:\Tutoriales\Mp3 ^| M:\Temp ^| h:\Temp ^| F:\Temp\Mp3 -export-txt "%OutFile%",, Hide

SoundPlay, *64
MsgBox, Ended process!
ExitApp

Cancel:
ExitApp
To learn more about how to configure the search by dates: https://www.voidtools.com/support/everything/searching/#date_constants

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

Re: Find out files opened by an application

Post by wetware05 » 16 Apr 2023, 08:44

Hi.

The same script as the previous one, but to search for files between two dates (the last one not being the current one, because the previous one works for that purpose).

Code: Select all

DetectHiddenWindows, Off
OutFile = h:\LastFiles_MP3.m3u
App = d:\Utilidades\Everything\es.exe

if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}

FileDelete, %OutFile%

SearchGUI:
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID	
Gui, Search: Add, DateTime, x10 y16 w200 h20 vFDateTime
Gui, Search: Add, DateTime, x10 y46 w200 h20 vTDateTime
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Button, x225 y16 w65 h20 GSearch, Search
Gui, Search: Add, Button, x225 y46 w65 h20 gCancel, Cancel
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w300, Search
Return

#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::

Search:
Gui Search: Submit
FormatTime, DayF, %FDateTime%, dd/MM/yyyy
FormatTime, DayT, %TDateTime%, dd/MM/yyyy
TimeS:= DayF ".." DayT

RunWait,  %comspec% /c chcp 65001 & "%App%" dm:"%TimeS%" ext:mp3 G:\MP3\Temporal ^| I:\Tutoriales\MP3 ^| M:\MP3 ^| h:\Temporal\MP3 ^| F:\MP3 -export-txt "%OutFile%",, Hide
SoundPlay, *64
MsgBox, Ended process!

Cancel:
ExitApp

User avatar
andymbody
Posts: 957
Joined: 02 Jul 2017, 23:47

Re: Find out files opened by an application

Post by andymbody » 29 Oct 2023, 08:48

wetware05 wrote:
16 Apr 2023, 08:44
Thanks for all this info. I have not had a chance to read your most recent posts in this thread, but plan to. Just wanted to let you know that your posts on this topic are appreciated.

Post Reply

Return to “Ask for Help (v1)”