AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lock script - doesn't delete window list file on exit

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
electro5r
Guest





PostPosted: Sun Mar 14, 2010 8:14 pm    Post subject: Lock script - doesn't delete window list file on exit Reply with quote

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

PostPosted: Sun Mar 14, 2010 8:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Sun Mar 14, 2010 8:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
electro5r
Guest





PostPosted: Sat Mar 20, 2010 4:05 pm    Post subject: Reply with quote

Thanks! It works great!
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group