Categories
Microsoft Office Productivity Technology Windows

Stay Focussed – Stay OUT of Outlook!

One of my main productivity “sinks” is continually monitoring Outlook to see if any mails have arrived.

I have a rule set up that notifies me if an “important” email lands but for this to run, outlook needs to be running (minimised of course). I can’t resist the temptation to just “have a peek” outside my first thing in the morning, last thing at night email window.

To get around this I want to be “discouraged” from opening Outlook.

To implement this I have used Antonio Franca’s fantastic WinTrigger AutoHotkey script.

My amendment is to make it watch for the main Outlook window and when this becomes active, to get it to ask me to confirm if I really want to be using Outlook. If I hit No or leave it for 5 seconds then Outlook gets minimised again.

Here is my implementation of Antonio’s code:

;========================================================================
;
; Template:     WinTrigger (former OnOpen/OnClose)
; Description:  Act upon (de)activation/(un)existance of programs/windows
; Online Ref.:  http://www.autohotkey.com/forum/viewtopic.php?t=63673
;
; Last Update:  15/Mar/2010 17:30
;
; Created by:   MasterFocus
;               http://www.autohotkey.net/~MasterFocus/AHK/
;
; Thanks to:    Lexikos, for improving it significantly
;               http://www.autohotkey.com/forum/topic43826.html#267338
;
;========================================================================
;
; This template contains two examples by default. You may remove them.
;
; * HOW TO ADD A PROGRAM to be checked upon (de)activation/(un)existance:
;
; 1. Add a variable named ProgWinTitle# (Configuration Section)
; containing the desired title/ahk_class/ahk_id/ahk_group
;
; 2. Add a variable named WinTrigger# (Configuration Section)
; containing the desired trigger (“Exist” or “Active”)
;
; 3. Add labels named LabelTriggerOn# and/or LabelTriggerOff#
; (Custom Labels Section) containing the desired actions
;
; 4. You may also change CheckPeriod value if desired
;
;========================================================================

#Persistent

; —— —— CONFIGURATION SECTION —— ——
SetTitleMatchMode 2
; Program Titles
;ProgWinTitle1 = ahk_class rctrl_renwnd32
ProgWinTitle1 = Microsoft Outlook
WinTrigger1 = Active

; SetTimer Period
CheckPeriod = 200

; —— END OF CONFIGURATION SECTION —— ——

SetTimer, LabelCheckTrigger, %CheckPeriod%
Return

; —— —— ——

LabelCheckTrigger:
While ( ProgWinTitle%A_Index% != “” && WinTrigger := WinTrigger%A_Index% )
if ( !ProgRunning%A_Index% != !Win%WinTrigger%( ProgWinTitle := ProgWinTitle%A_Index% ) )
GoSubSafe( “LabelTriggerO” ( (ProgRunning%A_Index% := !ProgRunning%A_Index%) ? “n” : “ff” ) A_Index )
Return

; —— —— ——

GoSubSafe(mySub)
{
if IsLabel(mySub)
GoSub %mySub%
}

; —— —— CUSTOM LABEL SECTION —— ——

LabelTriggerOn1:
;    winget    isMax, MinMax, %ProgWinTitle1%
;    msgbox    %isMax%
msgbox 4, Stay Focussed, Are you sure you want to read your mails?, 5
ifmsgbox    Yes
winmaximize    %ProgWinTitle1%
else
winminimize    %ProgWinTitle1%
return
LabelTriggerOff1:
;  MsgBox % “A_ThisLabel:`t” A_ThisLabel “`nProgWinTitle:`t” ProgWinTitle “`nWinTrigger:`t” WinTrigger
Return

; —— END OF CUSTOM LABEL SECTION —— ——

If you are in e-mail processing mode simply pause or stop the script!

You can of course follow the instructions in the script to watch for multiple windows and take action on each of them.

I hope you find it as useful as I do.

;========================================================================

;

; Template:     WinTrigger (former OnOpen/OnClose)

; Description:  Act upon (de)activation/(un)existance of programs/windows

; Online Ref.:  http://www.autohotkey.com/forum/viewtopic.php?t=63673

;

; Last Update:  15/Mar/2010 17:30

;

; Created by:   MasterFocus

;               http://www.autohotkey.net/~MasterFocus/AHK/

;

; Thanks to:    Lexikos, for improving it significantly

;               http://www.autohotkey.com/forum/topic43826.html#267338

;

;========================================================================

;

; This template contains two examples by default. You may remove them.

;

; * HOW TO ADD A PROGRAM to be checked upon (de)activation/(un)existance:

;

; 1. Add a variable named ProgWinTitle# (Configuration Section)

; containing the desired title/ahk_class/ahk_id/ahk_group

;

; 2. Add a variable named WinTrigger# (Configuration Section)

; containing the desired trigger (“Exist” or “Active”)

;

; 3. Add labels named LabelTriggerOn# and/or LabelTriggerOff#

; (Custom Labels Section) containing the desired actions

;

; 4. You may also change CheckPeriod value if desired

;

;========================================================================

#Persistent

; —— —— CONFIGURATION SECTION —— ——

SetTitleMatchMode 2

; Program Titles

;ProgWinTitle1 = ahk_class rctrl_renwnd32

ProgWinTitle1 = Microsoft Outlook

WinTrigger1 = Active

; SetTimer Period

CheckPeriod = 200

; —— END OF CONFIGURATION SECTION —— ——

SetTimer, LabelCheckTrigger, %CheckPeriod%

Return

; —— —— ——

LabelCheckTrigger:

While ( ProgWinTitle%A_Index% != “” && WinTrigger := WinTrigger%A_Index% )

if ( !ProgRunning%A_Index% != !Win%WinTrigger%( ProgWinTitle := ProgWinTitle%A_Index% ) )

GoSubSafe( “LabelTriggerO” ( (ProgRunning%A_Index% := !ProgRunning%A_Index%) ? “n” : “ff” ) A_Index )

Return

; —— —— ——

GoSubSafe(mySub)

{

if IsLabel(mySub)

GoSub %mySub%

}

; —— —— CUSTOM LABEL SECTION —— ——

LabelTriggerOn1:

;           winget   isMax, MinMax, %ProgWinTitle1%

;           msgbox            %isMax%

msgbox 4, Stay Focussed, Are you sure you want to read your mails?, 5

ifmsgbox          Yes

winmaximize      %ProgWinTitle1%

else

winminimize       %ProgWinTitle1%

return

LabelTriggerOff1:

;  MsgBox % “A_ThisLabel:`t” A_ThisLabel “`nProgWinTitle:`t” ProgWinTitle “`nWinTrigger:`t” WinTrigger

Return

; —— END OF CUSTOM LABEL SECTION —— ——

2 replies on “Stay Focussed – Stay OUT of Outlook!”

Hi Ross
I have been looking at this code because I think it could be of great benefit in my work. I only partially underastand the mechanics of it. I was wondering if I described the process that I do you might with your experience of using it say whether it would /should work in my scenario.
I use a a handheld scanner to scan a label that is on a chart This scanner is linked to my pc and the scanned image opens in a window on the pc screen. On this window I need to press an ok button, which brings up another window which has 4 buttons one of which I also need to click. This in turn brings up notepad with the text that I have scanned and I copy and paste this to excel for filtering etc There are thousand of these that need to be done on a regularly basis . If I had a script that got activated as soon as first window became active so that I didnt have to go near the pc, well you can see how how this would make it alot more efficient. I have tried to grasp the wintrigger code
it is heavy going . I am very willing to to take any advice you might have or direct me to where I might get a better understanding of this code

Regards Eugene

This sounds absolutely do-able – but I can only do basics with AutoHotkey.
You will get a better response if you post your comment on the autohotkey site or contact the actual author of the code above (see the comments at the top of the code)

Leave a Reply

Your email address will not be published. Required fields are marked *