AutoHotkey Community

It is currently May 27th, 2012, 5:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: March 14th, 2010, 9:14 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 9:45 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 9:47 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
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

* *  *

* *  *



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 5:05 pm 
Thanks! It works great!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], HotkeyStick, mrhobbeys and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group