My Technical Notes

Monday, 4 March 2013

Loading Apps On Startup with Autohotkey

Following script is being used to load Outlook and Firefoxand kill communicator.exe which is part of Lync.


#Persistent
#SingleInstance Force

SetTitleMatchMode, 2

run, Outlook
SetTimer, WaitForOutlookToOpen, 100
return

WaitForOutlookToOpen:
 ; outlook
 If WinExist("x.y@leicester.gov.uk")
 {
  SetTimer, WaitForOutlookToOpen, Off
  run, FireFox 
  Runwait, taskkill /im communicator.exe /f
  ExitApp ; exit from the script
 }
return

The above script uses a technique where it waits for Outlook to open by checking if a window exists with (part of) the title "x.y@leicester.gov.uk" which Outlook has. It uses a timer for this.

However there is a better way of doing this with the WinWaitActive function, which pauses the current thread until a window is active:


#SingleInstance Force

SetTitleMatchMode, 2

run, Outlook
WinWaitActive, x.y@leicester.gov.uk
run, FireFox 
Runwait, taskkill /im communicator.exe /f

No comments: