Reputation: 21
I was wondering if it's possible to make a script where it brings one specific application in focus every 12 min and then minimizes it instantly.
So to summarize:
So far i only found that minimizing it will make the previous app come in focus again.
Upvotes: 2
Views: 13395
Reputation:
Yes, this is definitely something you can do in AutoHotkey. The links below are to the AutoHotkey help document for the specific items you mentioned.
You have at least a couple options for this. You could use a combination of Loop
and Sleep
or SetTimer
by itself. I'd recommend SetTimer
but familiarizing yourself with the other two is beneficial as well.
https://www.autohotkey.com/docs/commands/Loop.htm
https://www.autohotkey.com/docs/commands/Sleep.htm
https://www.autohotkey.com/docs/commands/SetTimer.htm
There are a lot of window commands in AutoHotkey. These two are for what you specifically asked:
https://www.autohotkey.com/docs/commands/WinActivate.htm
https://www.autohotkey.com/docs/commands/WinMinimize.htm
Depending on why you need to have a window focused, there may be a different way of accomplishing what you need. If you need to type something in a certain window every 12 min., you could also use ControlSend
without having to activate it.
Here is an example to get you started:
f1:: ; f1 will toggle your script to run
bT := !bT ; this is the toggle variable
If bT
{
GoSub , lTimer ; triggers the timer sub to run immediately since SetTimer has to wait for period to expire on first run
SetTimer , lTimer , 2500 ; this is in milliseconds, 12min = 720000ms
}
Else
SetTimer , lTimer , Off
Return
lTimer: ; timer sub
If WinExist( "EEHotkeys" ) ; change EEHotkeys to be the name of your window in all places shown
{
WinActivate , EEHotkeys
WinWaitActive , EEHotkeys
WinMinimize , EEHotkeys
}
Return
EDIT: As suggested by samthecodingman in the comments, you could alternatively get the active window's title, activate your window, then reactivate the original window.
lTimer: ; timer sub
If WinExist( "EEHotkeys" ) ; change EEHotkeys to be the name of your window in all places shown
{
WinGetActiveTitle , sActiveWindow
WinActivate , EEHotkeys
WinWaitActive , EEHotkeys
WinActivate , %sActiveWindow%
}
Return
Upvotes: 2