The other approaches are probably better. But I've got a set up that adds a list to a GUI such that when you click an item in this list, it'll launch the file/program. This code is messy with stray lines commented out and some weird if/else sequencing, but it seems to work... (Though I realized I never added the functionality to open Notepad files, though they were being logged. And this code was written over a year ago.)
The basis is that you identify the active window and process, exclude it if you don't want to log it, add the file name and file location into an array, add the file name into a Listbox and if you click in the listbox, it'll run the file location associated with that file name. The messiest part is getting the file location, which is on a program-by-program basis where it automatically launches the Save As dialog to capture that information.
Just throwing this out there in case it's of any use to anybody. (Oh, I didn't include a
Gui, Show in this code... Probably put before the WindowLogger: line; I haven't actually tested this code, it's snippets from a much larger project.) It might be combined with the ideas presented above.
Code: Select all
Gui, Add, Listbox, % "x10 y1000 w" viewable-20 " r4 vWindowLog gWindowExecution", Slide Pane
SetTimer, WindowLogger, 1000
Windows:=[]
;If (activewindow="Slide Pane") || (activewindow="Slide Pane.ahk") || (activewindow="File Explorer") || (activewindow="Save As") || (activewindow="Task Switching"
GroupAdd, groupNoSaveAs, Save As
GroupAdd, groupNoSaveAs, Confirm Save As
IgnoreLog:="Slide Pane,Slide Pain.ahk,File Explorer,Save As,Task Switching,Opening - Word,Confirm Save As,Print"
WindowLogger:
ListLines, Off
WinGetActiveTitle, activewindow
;If (activewindow="Slide Pane") || (activewindow="Slide Pane.ahk") || (activewindow="File Explorer") || (activewindow="Save As") || (activewindow="Task Switching")
WinGet, activeprocess, ProcessName, %activewindow%
If (activewindow="Save As")
{
WinWaitClose, Save As ahk_exe %activeprocess%
WinGetActiveTitle, activewindowTWO
Windows[activeWindowTWO]:=""
loggedwindow:=""
Sleep 1000
}
If activewindow in %IgnoreLog%
return
If !activewindow
return
If (activeprocess!="firefox.exe") && (activeprocess!="chrome.exe") && (activeprocess!="palemoon.exe") && (activeprocess!="notepad++.exe")
; Then it's not a browser
If (activewindow!=loggedwindow)
{
windowlist:=RegExReplace(windowlist, "\Q|" activewindow "\E", "")
windowlist:="|" activewindow windowlist
GuiControl,, WindowLog, %windowlist%
loggedwindow:=activewindow
}
else
return
If Windows[activewindow]
return ; known issue - saving a file in a new location
If (activeprocess="explorer.exe")
{
ControlGetText, TW, ToolbarWindow323, %activewindow%
address:=SubStr(TW,10)
initial_ad:=SubStr(address,2,2)
If (initial_ad != ":\")
address:="C:\Users\%A_UserName%\" . address
Windows[activewindow]:=address
}
If (activeprocess="AcroRd32.exe")
{
Send ^+s
WinWait, Save As,,2 ; ahk_exe %activeprocess% ; Was WinWaitActive
If ErrorLevel
{
Send ^+s
WinWait, Save As,,2
If ErrorLevel
{
loggedwindow:=""
return
}
}
WinMove, Save As, 0, 0, 0, 0
ControlGetText, TW, ToolbarWindow325, Save As
address:=SubStr(TW,10)
ControlGetText, file, Edit1, Save As
initial_ad:=SubStr(address,2,2)
If (initial_ad != ":\")
address:="C:\Users\%A_UserName%\" . address
address.="\" file
WinClose, Save As
Windows[activewindow]:=address
;MsgBox % address "`n" activewindow "`n" Windows[activewindow]
}
If (activeprocess="winword.exe" || activeprocess="excel.exe")
{
Send {F12}
WinWait, Save As,,2
If ErrorLevel
{
Send {F12}
WinWait, Save As,,2
If ErrorLevel
{
loggedwindow:=""
return
}
}
ControlGetText, TW, ToolbarWindow325, Save As
addresS:=SubStr(TW,10)
ControlGetText, file, Edit1, Save As
initial_ad:=SubStr(Address,2,2)
If (initial_ad != ":\")
address:="C:\Users\%A_UserName%\" address
address.="\" file
WinClose, Save As
Windows[activewindow]:=address
}
If (activeprocess="notepad.exe")
{
WinMenuSelectItem, %activewindow%,,File, Save As
WinWait, Save As
DetectHiddenWindows, On
WinHide, Save As
ControlGetText, TW, ToolbarWindow324, Save As
address:=SubStr(TW,10) ; trims off the "Address: " prefix
ControlGetText, file, Edit1, Save As
initial_ad:=SubStr(Address,2,2) ; We want to check if this has the C:\Users\%A_UserName% prefix or not. Things like Documents\Folder\File.txt are possible in this address bar.
if (initial_ad != ":\")
address:="C:\Users\%A_UserName%\" address
address.="\" file
WinClose, Save As
Windows[activewindow]:=address
}
return
WindowExecution:
GuiControlGet, output,, WindowLog
Tooltip % Windows[output]
If (Windows[output])
Run % Windows[output]
Sleep 1000
Tooltip
return