I asked for help on the forum a while back on making a script that would hide all windows and lock the computer. I tweaked it to make two versions:
One that would just hide all windows
and another that would hide all windows and hide the taskbar, desktop etc
I can't seem to figure out how to make the script delete the file that keeps the list of windows that were hidden when the script exits.
It will do it when I press a key combination though. So the problem is that the file gets huge and takes forever to unhide windows.
Is there a way to make the script delete the file when I right click the icon and select exit?
Code:
#Persistent
SetTimer, Hide_Windows, 900000 ; Run this every 15 minutes
Return
OnExit, OnnExit
return
Hide_Windows: ; The following code will run with the timer (every 15 minutes)
#z:: ; Or when you press Windows_key + z
WinGet, id, List,,,Program Manager ; makes an array of every visible window on the system
Titles_List = ; set this to empty to avoid duplication
Loop %id% ; loop as many times as there are windows
{
this_id := id%A_Index% ; Title now equals the Unique ID of a specific window each time the loop runs
Titles_List = %Titles_List%%this_id%`, ; form the unique window IDs into a comma separated list
WinGetTitle, This_title, ahk_id %this_id%
WinHide, %this_title% ; hide each window after it ID is listed
}
FileAppend, %Titles_List%, C:\Hidden_Windows.txt
Return
#p::
SetTimer, Hide_Windows, 5000 ; Press Windows_key + x to run the same code every five seconds
Return
OnnExit:
#c::
SetTimer, Hide_Windows, Off ; Press Windows_key + c (or exit the program) to stop running the Hide code
FileRead, Titles_List, C:\Hidden_Windows.txt ; Get the saved list of hidden Window ID's
Loop, Parse, Titles_List, `, ; act on each in turn
{
WinShow, ahk_id%A_Space%%A_LoopField%
}
FileDelete, C:\Hidden_Windows.txt
ExitApp
Return
Return
#x::
FileRead, Titles_List, C:\Hidden_Windows.txt ; Get the saved list of hidden Window ID's
Loop, Parse, Titles_List, `, ; act on each in turn
{
WinShow, ahk_id%A_Space%%A_LoopField%
}
Return
Thanks