; Run Timer 0.97 ; Tested on WinXP Home IniFile = RunTimer.ini Alerter_OnceSetWeek = %A_MDay% Alerter_OnceSetMonth = %A_Mon% Alerter_CheckYear = %A_Year% NextYear := Alerter_CheckYear + 1 SleepFor = 750 IfExist, RunTimer.ico Menu, Tray, Icon, RunTimer.ico else Menu, Tray, Icon, %SystemRoot%\system32\SHELL32.dll, 12 StopTimer: Alerter_TimerWindowDisp = 1 Menu, Tray, DeleteAll Menu, Tray, NoStandard Menu, Tray, Add, Show Alarm, ShowAlarm Menu, Tray, NoDefault Menu, Tray, Disable, Show Alarm Menu, Tray, Add, Stop Timer, StopTimer Menu, Tray, Disable, Stop Timer Menu, Tray, Click, 1 Menu, Tray, Add, Help Menu, Tray, Add, About Menu, Tray, Add, Exit IniRead, Alerter_WriteToIni, %IniFile%, Store Settings, Def_Write, 0 IniRead, Alerter_SetHour, %IniFile%, Default, Def_Hour, 7 IniRead, Alerter_SetMinute, %IniFile%, Default, Def_Minute, 30 IniRead, Alerter_TODbox, %IniFile%, Default, Def_TODbox, 1 IniRead, Alerter_SetAction, %IniFile%, Default, Def_SetAction, 1 IniRead, Alerter_SetTimerOptions, %IniFile%, Default, Def_SetTimerOptions, 2 IniRead, Alerter_ForceShutdown, %IniFile%, Default, Def_ForceShutdown, 0 IniRead, Alerter_RunFile, %IniFile%, Default, Def_RunFile, C:\Program Files IniRead, Alerter_WeekSetWeek, %IniFile%, Default, Def_WeekSetWeek, 1 IniRead, Alerter_PlayChime, %IniFile%, Default, Def_PlayChime, 0 IniRead, Alerter_KillAfterExecution, %IniFile%, Default, Def_KillOnExecute, 1 IniRead, Alerter_PosX, %IniFile%, Window Position, Def_PosX, 250 IniRead, Alerter_PosY, %IniFile%, Window Position, Def_PosY, 250 loop { if (Alerter_PosX > (A_ScreenWidth - 20)) Alerter_PosX -= 2 else break } loop { if (Alerter_PosY > (A_ScreenHeight - 60)) Alerter_PosY -= 2 else break } ShowGui: Gui +ToolWindow Gui, Add, Text, x5 y5, Time: Gui, Font, W900 Gui, Add, Text, x60 y4, : Gui, Font, W400 Gui, Add, Edit, x35 y2 w25 vAlerter_SetHour Default, %Alerter_SetHour% Gui, Add, Edit, x65 y2 w25 vAlerter_SetMinute, %Alerter_SetMinute% Gui, Add, DropDownList, x93 y2 w40 AltSubmit Choose%Alerter_TODbox% vAlerter_TODbox, AM|PM Gui, Add, UpDown, h5 w25 x35 y24 Horz -16 Range-1-1 gUpDownHour vAlerter_UpDownHour Gui, Add, UpDown, h5 w25 x65 y24 Horz -16 Range-1-1 gUpDownMinute vAlerter_UpDownMinute Gui, Add, Button, x2 y31 gConfigureAction, &Options Gui, Add, Button, x59 y31 gSetTime, O&K Gui, Add, Button, x87 y31 gKill, &Cancel Gui, Show, X%Alerter_PosX% Y%Alerter_PosY%, Run Timer return SetTime: Gui, Submit, Nohide WinGetPos, Alerter_PosX, Alerter_PosY Gui, Destroy Alerter_TimerWindowDisp = 0 Goto CheckTime GoodToGo: SaveSettings: if (Alerter_WriteToIni = 0) Goto SkipWriting IniWrite, %Alerter_WriteToIni%, %IniFile%, Store Settings, Def_Write IniWrite, %Alerter_SetHour%, %IniFile%, Default, Def_Hour IniWrite, %Alerter_SetMinute%, %IniFile%, Default, Def_Minute IniWrite, %Alerter_TODbox%, %IniFile%, Default, Def_TODbox IniWrite, %Alerter_SetAction%, %IniFile%, Default, Def_SetAction IniWrite, %Alerter_SetTimerOptions%, %IniFile%, Default, Def_SetTimerOptions IniWrite, %Alerter_ForceShutdown%, %IniFile%, Default, Def_ForceShutdown IniWrite, %Alerter_RunFile%, %IniFile%, Default, Def_RunFile IniWrite, %Alerter_WeekSetWeek%, %IniFile%, Default, Def_WeekSetWeek IniWrite, %Alerter_PlayChime%, %IniFile%, Default, Def_PlayChime IniWrite, %Alerter_KillAfterExecution%, %IniFile%, Default, Def_KillOnExecute IniWrite, %Alerter_PosX%, %IniFile%, Window Position, Def_PosX IniWrite, %Alerter_PosY%, %IniFile%, Window Position, Def_PosY SkipWriting: Alerter_Hour := Alerter_SetHour Alerter_Minute := Alerter_SetMinute if (Alerter_TODbox = 2 && Alerter_Hour != 12) Alerter_Hour += 12 if (Alerter_TODbox = 1 && Alerter_Hour = 12) Alerter_Hour = 0 if Alerter_TODbox = 1 TOD = AM else TOD = PM Menu, Tray, Enable, Show Alarm Menu, Tray, Enable, Stop Timer Menu, Tray, Default, Show Alarm ; set message for traytip to display if (Alerter_SetAction = 1) Alerter_ShowMessage = Alarm will open a file, `n%Alerter_RunFile% else if (Alerter_SetAction = 2) { if (Alerter_ForceShutdown = 1) Alerter_ShowMessage = Alarm will (force) shut down the computer. else Alerter_ShowMessage = Alarm will shut down the computer. } else if (Alerter_SetAction = 3) { if (Alerter_ForceShutdown = 1) Alerter_ShowMessage = Alarm will (force) restart the computer. else Alerter_ShowMessage = Alarm will restart the computer. } else if (Alerter_SetAction = 4) Alerter_ShowMessage = Alarm will display a message box. else if (Alerter_SetAction = 5) Alerter_ShowMessage = Alarm will execute implemented AHK code. ShowAlarm: if (Alerter_SetTimerOptions = 1) { TrayTip, Run Timer, Alarm is set to go off every hour at *:%Alerter_Minute%. `n%Alerter_ShowMessage% Goto WaitLoopA } else if (Alerter_SetTimerOptions = 2) { TrayTip, Run Timer, Alarm is set for %Alerter_SetHour%:%Alerter_Minute% %TOD%. `n%Alerter_ShowMessage% Goto WaitLoopB } else if (Alerter_SetTimerOptions = 3) { Alerter_WeekDisp := ((Alerter_WeekSetWeek = "1") ? ("Sunday") : ( (Alerter_WeekSetWeek = "2") ? ("Monday") : ( (Alerter_WeekSetWeek = 3) ? ("Tuesday") : ( (Alerter_WeekSetWeek = 4) ? ("Wednesday") : ( (Alerter_WeekSetWeek = 5) ? ("Thursday") : ( (Alerter_WeekSetWeek = 6) ? ("Friday") : ( (Alerter_WeekSetWeek = 7) ("Saturday") ))))))) TrayTip, Run Timer, Alarm is set to go off on %Alerter_WeekDisp%s at %Alerter_SetHour%:%Alerter_Minute% %TOD%. `n%Alerter_ShowMessage% Goto WaitLoopC } else { Alerter_MonthDisp := ((Alerter_OnceSetMonth = "1") ? ("January") : ( ((Alerter_OnceSetMonth = "2") ? ("February") : ( ((Alerter_OnceSetMonth = "3") ? ("March") : ( ((Alerter_OnceSetMonth = "4") ? ("April") : ( ((Alerter_OnceSetMonth = "5") ? ("May") : ( ((Alerter_OnceSetMonth = "6") ? ("June") : ( ((Alerter_OnceSetMonth = "7") ? ("July") : ( ((Alerter_OnceSetMonth = "8") ? ("August") : ( ((Alerter_OnceSetMonth = "9") ? ("September") : ( ((Alerter_OnceSetMonth = "10") ? ("October") : ( ((Alerter_OnceSetMonth = "11") ? ("November") : ( ((Alerter_OnceSetMonth = "12") ? ("December") ))))))))))))))))))))))) TrayTip, Run Timer, Alarm is set to go off on %Alerter_MonthDisp% %Alerter_OnceSetWeek%`, %Alerter_CheckYear%`, at %Alerter_SetHour%:%Alerter_Minute% %TOD%. `n%Alerter_ShowMessage% Goto WaitLoopD } WaitLoopA: Loop { if (A_Min = Alerter_Minute) Goto Alarm Sleep, %SleepFor% } WaitLoopB: Loop { if (A_Hour = Alerter_Hour && A_Min = Alerter_Minute) Goto Alarm Sleep, %SleepFor% } WaitLoopC: Loop { if (A_WDay = Alerter_WeekSetWeek && A_Hour = Alerter_Hour && A_Min = Alerter_Minute) Goto Alarm Sleep, %SleepFor% } WaitLoopD: Loop { if (A_Year = Alerter_CheckYear && A_Mon = Alerter_OnceSetMonth && A_MDay = Alerter_OnceSetWeek && A_Hour = Alerter_Hour && A_Min = Alerter_Minute) Goto Alarm Sleep, %SleepFor% } ; Finally! The actual executing part... Alarm: if (Alerter_PlayChime = 1) { IfExist, RunTimer.wav { SoundPlay, RunTimer.wav SetTimer, KillWav, -30000 } else SoundBeep, 750, 500 ; Play a higher pitch for half a second. } if (Alerter_SetAction = 1) { Run %Alerter_RunFile% } else if (Alerter_SetAction = 2) { if (Alerter_ForceShutdown = 1) Shutdown, 12 else Shutdown, 8 } else if (Alerter_SetAction = 3) { if (Alerter_ForceShutdown = 1) Shutdown, 6 else Shutdown, 2 } else if (Alerter_SetAction = 4) { FormatTime, Alerter_DispTime,, dddd`, MMMM d`, h:mm tt Msgbox It is now %Alerter_DispTime% } else if (Alerter_SetAction = 5) { ; Enter your code/custom actions HERE! ; You could just create an ahk file to run with the open command... ; but if you're planning to compile so you can run it on a machine ; without AHK, the place to put your code is here. } Sleep, 10000 ; sometimes necessary so the function is carried out before the script closes if (Alerter_TimerWindowDisp = 1) return if (Alerter_SetTimerOptions != 4) { if (Alerter_KillAfterExecution = 0) { Sleep, 60000 if (Alerter_SetTimerOptions = 1) Goto WaitLoopA else if (Alerter_SetTimerOptions = 2) Goto WaitLoopB else if (Alerter_SetTimerOptions = 3) Goto WaitLoopC else if (Alerter_SetTimerOptions = 4) Goto WaitLoopD } } Kill: ExitApp return ConfigureAction: WinGetPos, Alerter_PosX, Alerter_PosY,,, Run Timer ifWinExist, Timer Options { WinActivate, Timer Options return } ; now loop to set all "check" variables to zero, then give 1 to the number whose radio was previously checked Loop { if (A_Index > 4) break Alerter_2Check%A_Index% = 0 } Alerter_2Check%Alerter_SetTimerOptions% = 1 ; and again for the first tab Loop { if (A_Index > 5) break Alerter_Check%A_Index% = 0 } Alerter_Check%Alerter_SetAction% = 1 Alerter_AdjustedPosY := Alerter_PosY + 75 if (Alerter_AdjustedPosY > (A_ScreenHeight - 185)) Alerter_AdjustedPosY := Alerter_AdjustedPosY - 250 Gui, 2:+ToolWindow Gui, 2:Add, Tab2, W215 H155 x-0 y+1, Action|Timer Gui, 2:Add, Radio, x14 y30 Checked%Alerter_Check1% vAlerter_SetAction, Open a &File Gui, 2:Add, Radio, x14 y47 Checked%Alerter_Check2%, &Shut Down Gui, 2:Add, Radio, x14 y64 Checked%Alerter_Check3%, &Restart Gui, 2:Add, Radio, x14 y81 Checked%Alerter_Check4%, &Message Box Gui, 2:Add, Radio, x14 y98 Checked%Alerter_Check5%, Other (&AHK) Gui, 2:Add, Button, x100 y30 gSelectFile, O&pen File Gui, 2:Add, Button, x160 y30 gDisplayToolTip, &? Gui, 2:Add, Checkbox, x100 y55 Checked%Alerter_ForceShutdown% vAlerter_ForceShutdown, Forc&e Gui, 2:Add, Text, x118 y68, Restart/`nShutdown Gui, 2:Add, Checkbox, x100 y95 Checked%Alerter_PlayChime% vAlerter_PlayChime, Pla&y Chime Gui, 2:Add, Checkbox, x100 y110 Checked%Alerter_WriteToIni% vAlerter_WriteToIni, Write to &ini Gui, 2:Add, Checkbox, x100 y125 Checked%Alerter_KillAfterExecution% vAlerter_KillAfterExecution, Kill after E&xecution Gui, 2:Add, Button, x14 y115 gSubmit2, O&K Gui, 2:Add, Button, x45 y115 gCancel2, &Cancel Gui, 2:Tab, 2 Gui, 2:Add, Radio, x14 y24 Checked%Alerter_2Check1% vAlerter_SetTimerOptions, Every &Hour Gui, 2:Add, Radio, x14 y41 Checked%Alerter_2Check2%, Every &Day Gui, 2:Add, Radio, x14 y58 Checked%Alerter_2Check3%, &Weekly Gui, 2:Add, Radio, x14 y75 Checked%Alerter_2Check4%, &Once Gui, 2:Add, DropDownList, x70 y55 w85 AltSubmit choose%Alerter_WeekSetWeek% vAlerter_WeekSetWeek, Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday Gui, 2:Add, DropDownList, x14 y91 w35 choose%Alerter_OnceSetWeek% vAlerter_OnceSetWeek, 01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31 Gui, 2:Add, DropDownList, x53 y91 w80 AltSubmit choose%Alerter_OnceSetMonth% vAlerter_OnceSetMonth, January|February|March|April|May|June|July|August|September|October|November|December Gui, 2:Add, DropDownList, x135 y91 w75 choose1 vAlerter_CheckYear, %Alerter_CheckYear%|%NextYear% Gui, 2:Add, Button, x14 y115 gSubmit2, O&K Gui, 2:Add, Button, x45 y115 gCancel2, &Cancel Gui, 2:Show, W215 H157 X%Alerter_PosX% Y%Alerter_AdjustedPosY%, Timer Options return Submit2: Gui, 2:Submit, Nohide if (Alerter_WriteToIni = 0) { IfExist, %A_ScriptDir%\%IniFile% IniWrite, %Alerter_WriteToIni%, %IniFile%, Store Settings, Def_Write Goto SkipWriting3 } IniWrite, %Alerter_SetHour%, %IniFile%, Default, Def_Hour IniWrite, %Alerter_SetMinute%, %IniFile%, Default, Def_Minute IniWrite, %Alerter_TODbox%, %IniFile%, Default, Def_TODbox IniWrite, %Alerter_SetAction%, %IniFile%, Default, Def_SetAction IniWrite, %Alerter_SetTimerOptions%, %IniFile%, Default, Def_SetTimerOptions IniWrite, %Alerter_ForceShutdown%, %IniFile%, Default, Def_ForceShutdown IniWrite, %Alerter_RunFile%, %IniFile%, Default, Def_RunFile IniWrite, %Alerter_WeekSetWeek%, %IniFile%, Default, Def_WeekSetWeek IniWrite, %Alerter_PlayChime%, %IniFile%, Default, Def_PlayChime IniWrite, %Alerter_KillAfterExecution%, %IniFile%, Default, Def_KillOnExecute SkipWriting3: Gui, 2:Destroy if (Alerter_RunFile = "") { RepeatNoFileMessage: Msgbox, 4, No File Defined, You chose to open a file`, but did not `nset one. Do you wish to do so now? IfMsgBox Yes { FileSelectFile, Alerter_RunFile, 35, %Def_RunFile%, Run Timer - Select A File Or Program if (Alerter_RunFile = "") Goto RepeatNoFileMessage } else MsgBox With no file defined`, the alarm will do nothing when it goes off. } WinActivate, Run Timer return return SelectFile: FileSelectFile, Alerter_RunFile, 35, %Def_RunFile%, Run Timer - Select A File Or Program return Cancel2: 2GuiClose: Gui, 2:Destroy WinActivate, Run Timer return GuiClose: if (Alerter_WriteToIni = 0) Goto SkipWriting2 WinGetPos, Alerter_PosX, Alerter_PosY,,, Run Timer IniWrite, %Alerter_PosX%, %IniFile%, Window Position, Def_PosX IniWrite, %Alerter_PosY%, %IniFile%, Window Position, Def_PosY SkipWriting2: ExitApp return UpDownHour: Gui, Submit, Nohide Alerter_SetHour += %Alerter_UpDownHour% Alerter_SetHour := ((Alerter_SetHour <= 1) ? (1) : ( ((Alerter_SetHour >= 12) ? (12) : ( (Alerter_SetHour) )))) ; if it's not 1 - 12, fix it GuiControl, , Alerter_SetHour, %Alerter_SetHour% Alerter_UpDownHour = 0 GuiControl, , Alerter_UpDownHour, %Alerter_UpDownHour% return UpDownMinute: Gui, Submit, Nohide Alerter_SetMinute += %Alerter_UpDownMinute% Alerter_SetMinute := ((Alerter_SetMinute <= 0) ? (0) : ( ((Alerter_SetMinute >= 59) ? (59) : ( (Alerter_SetMinute) )))) if (Alerter_SetMinute <= 9) Alerter_SetMinute = 0%Alerter_SetMinute% GuiControl, , Alerter_SetMinute, %Alerter_SetMinute% Alerter_UpDownMinute = 0 GuiControl, , Alerter_UpDownMinute, %Alerter_UpDownMinute% return CheckTime: if (Alerter_SetHour < 1 || Alerter_SetHour > 12) { Msgbox Please set the hour between 1 and 12 failure = 1 } if (Alerter_SetMinute < 0 || Alerter_SetMinute > 59) { Msgbox Please set the minute between 0 and 59 failure = 1 } if (failure = 1) { failure = 0 Goto ShowGui } else Goto GoodToGo return DisplayToolTip: if (Alerter_RunFile = "") ToolTip, No File Selected. else ToolTip, File: %Alerter_RunFile% SetTimer, RemoveToolTip, -10000 MouseGetPos, Alerter_X, Alerter_Y loop { Sleep, 40 MouseGetPos, Alerter_X2, Alerter_Y2 if (Alerter_X != Alerter_X2 || Alerter_Y != Alerter_Y2) break } SetTimer, RemoveToolTip, -10 return RemoveToolTip: ToolTip return ; apparently this is necessary to make the program 'let go' of the wav file KillWav: SoundPlay, thisfiledoesntexist.wav return Help: Alerter_HelpMessage = ( to be continued... ) Msgbox, 64, Run Timer v0.97, %Alerter_HelpMessage% return About: Alerter_AboutMessage = ( contact info: stevendement@gmail.com Written in AutoHotkey scripting language Source code is available at AutoHotkey.net ) Msgbox, 64, Run Timer v0.97, %Alerter_AboutMessage% return Exit: ExitApp return