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 —— ——

About 

    Find more about me on:
  • facebook
  • flickr
  • googleplus
  • linkedin
  • skype
  • twitter
  • youtube

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>