 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
electro5r Guest
|
Posted: Sun Mar 14, 2010 8:14 pm Post subject: Lock script - doesn't delete window list file on exit |
|
|
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 |
|
| Back to top |
|
 |
closed
Joined: 07 Feb 2008 Posts: 509
|
Posted: Sun Mar 14, 2010 8:45 pm Post subject: |
|
|
| Code: | #Persistent
SetTimer, Hide_Windows, 900000 ; Run this every 15 minutes
Return
OnExit, OnnExit
return |
remove the return like this:
| Code: | #Persistent
SetTimer, Hide_Windows, 900000 ; Run this every 15 minutes
OnExit, OnnExit
return |
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Sun Mar 14, 2010 8:47 pm Post subject: |
|
|
The "OnExit" instruction is never being executed because program flow ends before that instruction is encountered.
Remove the "return " instruction after "settimer" so that the "OnExit" instruction is part of the autoexecute section of the script.
Right now it is an 'orphan' with it _never_ being called.
| Code: | #Persistent
SetTimer, Hide_Windows, 900000 ; Run this every 15 minutes
Return ;<----------------------- remove this line
OnExit, OnnExit
return
* * *
* * *
|
|
|
| Back to top |
|
 |
electro5r Guest
|
Posted: Sat Mar 20, 2010 4:05 pm Post subject: |
|
|
| Thanks! It works great! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|