Monday, November 17, 2014

Autohotkey script to generate a BIRT report from Eclipse Report Design perspective

An Autohotkey script to generate a BIRT report from Eclipse when using the Report Design perspective (Run → View Report → In Web Viewer/As Doc/As PDF etc). I use this because, frustratingly, there are no key bindings to generate a report and no accelerator keys under the View Report menu in Eclipse since Luna Release (4.4.0).

; In Eclipse, run BIRT report
#IfWinActive, Report Design - .*rptdesign - Eclipse
   +F8::
      SendInput, {ALT}rr{down}{down}{down}{down}{down}{down}{down}{enter}
      Sleep, 800
      clickOkToGenerateBirtReport()
   Return
#IfWinActive

; Eclipse Only - but a torn out window panel of it.
#IfWinActive, ahk_class #32770
   ; View BIRT report
   +F8::
      SendInput, {F12}
      Sleep, 100
      SendInput, {ALT}rr{down}{down}{down}{down}{down}{down}{down}{enter}
      Sleep, 1000
      clickOkToGenerateBirtReport()
   Return
#IfWinActive

clickOkToGenerateBirtReport() {
   ; If we can see the Parameter Selection Page, click OK.
   ; Look for it ten times, sleeping in between.
   Loop, 100
   {
      if WinActive("PARAMETER SELECTION PAGE") {
         WinGet, IEControlList, ControlList, ahk_class SWT_Window0
         Loop, Parse,IEControlList, `n
         {
            if (A_LoopField = "Internet Explorer_Server1") {
               MouseClick, left,  630,  580
               return true
            }
         }
      }
      Sleep, 200
   }
   MsgBox Sorry, couldn't find the button to click on.
   return false
}

Note that there are two conditions under which the trigger will execute. The first one is when I am in the main window of Eclipse: (IfWinActive, Report Design - .*rptdesign - Eclipse). The second is for when I am using Eclipse spread across two monitors and have torn off panels to sit on the other monitor and have run the command: IfWinActive, ahk_class #32770.