#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=WebAlarmApp.ico #AutoIt3Wrapper_outfile=WebAlarmApp0.1.1.0.exe #AutoIt3Wrapper_Res_Description=Application to open web browser and go to a media stream at a specified time #AutoIt3Wrapper_Res_Fileversion=0.1.1.0 #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: Jason Bogle Script Title: Web Alarm Script Version: 0.1.1.0 Updated From: 0.1.0.0 on 2/20/2010 Script Function: Application to open web browser and go to a media stream to work as an alarm. Works on: Windows Vista/7 #ce ---------------------------------------------------------------------------- ; Script Start #include #include #include #include #include #include #include #include #include Opt("TrayMenuMode", 1) Opt("WinTitleMatchMode", 2) ;Opt("TrayIconDebug", 1) ; For debugging TraySetState(1) #cs - Global Variables to be used in future versions ----------------------------------------------------------------- Global $SunAlarmActive, $SunAlarmHour, $SunAlarmMinute, $SunAlarmAMPM, $SunAlarmTarget, $SunAlarmTargetName Global $MonAlarmActive, $MonAlarmHour, $MonAlarmMinute, $MonAlarmAMPM, $MonAlarmTarget, $MonAlarmTargetName Global $TueAlarmActive, $TueAlarmHour, $TueAlarmMinute, $TueAlarmAMPM, $TueAlarmTarget, $TueAlarmTargetName Global $WedAlarmActive, $WedAlarmHour, $WedAlarmMinute, $WedAlarmAMPM, $WedAlarmTarget, $WedAlarmTargetName Global $ThurAlarmActive, $ThurAlarmHour, $ThurAlarmMinute, $ThurAlarmAMPM, $ThurAlarmTarget, $ThurAlarmTargetName Global $FriAlarmActive, $FriAlarmHour, $FriAlarmMinute, $FriAlarmAMPM, $FriAlarmTarget, $FriAlarmTargetName Global $SatAlarmActive, $SatAlarmHour, $SatAlarmMinute, $SatAlarmAMPM, $SatAlarmTarget, $SatAlarmTargetName #ce ------------------------------------------------------------------------------------------------------------------ Global $alarm24Hour, $alarm24HrTime, $alarm12Hour, $alarm12HrTime, $alarmHour, $alarmMinute, $time, $desiredVolume, $alarmCheck, $alarmTime Global $browserHomeTitle, $target, $targetName, $AM_PM, $closeCheck, $closeHour, $closeMinute, $closeAM_PM, $close24Hour, $closeTime Global $alarmCheck1, $closeCheck1, $alarmHour1, $alarmMinute1, $AM_PM1, $Browser, $browserHomeTitle1, $closeAM_PM1, $closeHour1 Global $closeMinute1, $desiredVolume1, $target1, $targetName1, $daily, $daily1, $openUserInterface, $Okay, $ExitProg, $openUserInterface, $exititem TraySettings() OpenGUI() #Region ### Functions ### ; Executes the Alarm Func AlarmExecute() If ($alarmCheck == 1) Then ; Check to make sure the alarm should execute While ($time <> $alarm24HrTime And $alarmCheck == 1) ; Continue to check until either the time has come or the alarm has been deactivated $time = @HOUR & ":" & @MIN $alarmCheck = GUICtrlRead($alarmCheck1) CheckTray() ; If a tray button is clicked, execute its function IfClick() ; If a GUI button is clicked, execute its function WEnd If ($time == $alarm24HrTime And $alarmCheck == 1) Then ; Check one more time to ensure the alarm does not execute on accident ControlVolume() ; Set the volume to the desired percentage OpenTargetAndExecute() ; Open the browser and go to the target URL CloseBrowserTabIfActive() ; Close the target if active desired by the user EndIf $daily = GUICtrlRead($daily1) ; Check $daily and $alarmCheck settings $alarmCheck = GUICtrlRead($alarmCheck1) $i = 0 ; Declare a counting variable and set it to zero While ($i < 600 And $alarmCheck == 1 And $daily == 1) ; Wait one minute until moving on ... Continue to check $daily and $alarmCheck settings Sleep(100) $daily = GUICtrlRead($daily1) $alarmCheck = GUICtrlRead($alarmCheck1) CheckTray() ; If a tray button is clicked, execute its function IfClick() ; If a GUI button is clicked, execute its function $i += 1 WEnd While ($alarmCheck == 1 And $daily == 1) ; If $daily and $alarmCheck are active, then coninue on until inactive $time = @HOUR & ":" & @MIN $daily = GUICtrlRead($daily1) $alarmCheck = GUICtrlRead($alarmCheck1) AlarmExecute() WEnd EndIf EndFunc ;==>AlarmExecute ; Gets the settings for the alarm Func AlarmCalculations() ; Convert the desired alarm time to military time for the computer If ($AM_PM == "PM" And $alarmHour <> 12) Then ; Add 12 to the hour if PM is selected $alarm24Hour = $alarmHour + 12 ElseIf ($AM_PM == "AM" And $alarmHour == 12) Then ; If AM is selected and hour = 12, set hour to zero $alarm24Hour = 00 Else ; If AM is selected, hour stays the same $alarm24Hour = $alarmHour EndIf ; Put a zero in front of a single digit so the computer can accurately compare it to the real time If $alarm24Hour < 10 Then $alarm24Hour = 0 & $alarm24Hour EndIf ; Convert the desired closing time to military time for the computer If ($closeAM_PM == "PM" And $closeHour <> 12) Then ; Add 12 to the hour if PM is selected $close24Hour = $closeHour + 12 ElseIf ($closeAM_PM == "AM" And $closeHour == 12) Then ; If AM is selected and hour = 12, set hour to zero $close24Hour = 00 Else ; If AM is selected, hour stays the same $close24Hour = $alarmHour EndIf ; Put a zero in front of a single digit so the computer can accurately compare it to the real time If $close24Hour < 10 Then $close24Hour = 0 & $close24Hour EndIf $alarm24HrTime = $alarm24Hour & ":" & $alarmMinute ; Combine hour and minute $alarmTime = $alarmHour & ":" & $alarmMinute & " " & $AM_PM $closeTime = $close24Hour & ":" & $closeMinute $time = @HOUR & ":" & @MIN EndFunc ;==>AlarmCalculations ; Contols the speaker volume Func ControlVolume() Send("{VOLUME_DOWN 100}") ; Set the volume to zero $volumeUp = $desiredVolume / 2 ; volume increases by two, so divide the desired volume by two $volumeCount = 0 ; Set the counter to zero While $volumeCount < $volumeUp ; Turn the volume up to the desired volume Send("{VOLUME_UP}") $volumeCount += 1 WEnd EndFunc ;==>ControlVolume ; Opens the target site and exeutes commands Func OpenTargetAndExecute() Send("{BROWSER_HOME}") ; Open the user's default browser to the homepage Sleep(1000) ; Wait for the browser to open WinActivate($browserHomeTitle) ; Activate the window Send("^t") ; Open a new Sleep(1000) ; Wait for the tab Send($target & "{ENTER}") ; Send the target URL to the browser ... Hit "Enter" EndFunc ;==>OpenTargetAndExecute ; Closes the target if active Func CloseBrowserTabIfActive() $time = @HOUR & ":" & @MIN If ($closeCheck == 1) Then ; Check the $closeCheck value While ($time <> $closeTime And $closeCheck == 1) ; Continue to check values until one changes or reaches a certain point $time = @HOUR & ":" & @MIN $closeCheck = GUICtrlRead($closeCheck1) CheckTray() ; If a tray button is clicked, execute its function IfClick() ; If a GUI button is clicked, execute its function WEnd If (WinActive($targetName) <> 0 And $closeCheck == 1) Then ; If the target window $closeCheck are still active and $closeCheck, close the tab/window Send("^w") EndIf EndIf EndFunc ;==>CloseBrowserTabIfActive ; Tray operations Func TraySettings() $openUserInterface = TrayCreateItem("Open Web Alarm User Interface") TrayItemSetOnEvent($openUserInterface, "ShowGUI") ; Open the GUI if the $openUserInterface is clicked TrayCreateItem("") $exititem = TrayCreateItem("Exit") TrayItemSetOnEvent($exititem, "ExitApp") ; Exit the app/script if the $exititem is clicked EndFunc ;==>TraySettings ; Called by the "Exit" tray item Func ExitApp() Exit EndFunc ;==>ExitApp ; Builds the GUI and executes the code Func OpenGUI() #Region ### START GUI section ### $AlarmClock = GUICreate("Alarm Clock", 541, 412, 216, 182, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS)) GUISetIcon("D:\003.ico") $GroupBox1 = GUICtrlCreateGroup("", 8, 1, 521, 367) $desiredVolume1 = GUICtrlCreateSlider(9, 263, 517, 45) GUICtrlSetLimit($desiredVolume1, 100, 0) $Vol = GUICtrlCreateLabel("Volume", 14, 237, 70, 28) GUICtrlSetFont($Vol, 16, 400, 0, "MS Sans Serif") $alarmHour1 = GUICtrlCreateCombo("1", 135, 40, 41, 25) GUICtrlSetData($alarmHour1, "2|3|4|5|6|7|8|9|10|11|12") $alarmMinute1 = GUICtrlCreateCombo("00", 193, 40, 43, 25) GUICtrlSetData($alarmMinute1, "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|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59") $colon = GUICtrlCreateLabel(":", 181, 34, 9, 28) GUICtrlSetFont($colon, 14, 400, 0, "MS Sans Serif") $target1 = GUICtrlCreateInput("Pandora.com", 12, 155, 513, 21) $targetName1 = GUICtrlCreateInput("Pandora Radio", 12, 212, 512, 21) $browserHomeTitle1 = GUICtrlCreateInput("New Tab", 11, 99, 514, 21) $BrowserHomeLabel = GUICtrlCreateLabel("Your Browser Homepage Title", 13, 65, 258, 28) $TargetUR = GUICtrlCreateLabel("Desired Target URL", 10, 125, 169, 28) GUICtrlSetFont($TargetUR, 16, 400, 0, "MS Sans Serif") $TargetNameInpu = GUICtrlCreateLabel("Desired Target Name", 13, 183, 184, 28) GUICtrlSetFont($TargetNameInpu, 16, 400, 0, "MS Sans Serif") $timeLabel = GUICtrlCreateLabel("Alarm Time - Hour : Minute AM/PM", 12, 10, 298, 28) GUICtrlSetFont($timeLabel, 16, 400, 0, "MS Sans Serif") $AM_PM1 = GUICtrlCreateCombo("AM", 248, 40, 55, 25) GUICtrlSetData($AM_PM1, "PM") $Label1 = GUICtrlCreateLabel("Close Tab Time - Hour : Minute AM/PM", 189, 306, 335, 28) GUICtrlSetFont($Label1, 16, 400, 0, "MS Sans Serif") $closeHour1 = GUICtrlCreateCombo("1", 339, 338, 41, 25) GUICtrlSetData($closeHour1, "2|3|4|5|6|7|8|9|10|11|12") $Label2 = GUICtrlCreateLabel(":", 385, 332, 9, 28) GUICtrlSetFont($Label2, 14, 400, 0, "MS Sans Serif") $closeMinute1 = GUICtrlCreateCombo("00", 397, 338, 43, 25) GUICtrlSetData($closeMinute1, "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|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59") $closeAM_PM1 = GUICtrlCreateCombo("AM", 452, 338, 55, 25) GUICtrlSetData($closeAM_PM1, "PM") $closeCheck1 = GUICtrlCreateCheckbox("Close The Tab at the Specified Time", 132, 339, 196, 17) $alarmCheck1 = GUICtrlCreateCheckbox("Make Alarm Active", 313, 43, 114, 17) $daily1 = GUICtrlCreateCheckbox("Daily Alarm", 312, 70, 97, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("", -99, -99, 1, 1) $Okay = GUICtrlCreateButton("&OK", 354, 375, 75, 25, $WS_GROUP) $ExitProg = GUICtrlCreateButton("&Exit the Alarm", 451, 375, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 IfClick() WEnd EndFunc ;==>OpenGUI ; Checks for GUI actions Func IfClick() $nMsg = GUIGetMsg() ; Get the message from the GUI Select Case $nMsg = $GUI_EVENT_CLOSE ; Case to execute when the little red 'X' is clicked Exit Case $nMsg = $Okay ; Case to execute when the "Ok" button is clicked OkayClick() Case $nMsg = $ExitProg ; Case to execute when the "Exit the Alarm" button is clicked Exit EndSelect CheckTray() EndFunc ;==>IfClick ; Called when "Ok" is clicked Func CheckTray() $nMsg = TrayGetMsg() ; Get the message from the tray Select Case $nMsg = $openUserInterface ; Case to execute if "Open Web Alarm Interface" is clicked ShowGUI() Case $nMsg = $exititem ; Case to execute if "Exit" is clicked Exit EndSelect EndFunc ;==>CheckTray ; Function to activate when "Ok" is clicked Func OkayClick() MinimizeGUItoTray() ; Clear the window from the screen GetSettings() ; Sett all the variables AlarmCalculations() ; Calculated the time AlarmExecute() ; Execute the alarm EndFunc ;==>OkayClick ; Function that collects info from the GUI Func GetSettings() $browserHomeTitle = GUICtrlRead($browserHomeTitle1) ; Get the name (or partial name) of the homepage $desiredVolume = GUICtrlRead($desiredVolume1) ; Get the desired volume $target = GUICtrlRead($target1) ; Get the target URL $targetName = GUICtrlRead($targetName1) ; Get the title of the target $alarmHour = GUICtrlRead($alarmHour1) ; Get the desired hour for the alarm $alarmMinute = GUICtrlRead($alarmMinute1) ; Get the desired minute for the alarm $AM_PM = GUICtrlRead($AM_PM1) ; Did the user choose AM or PM for the alarm? $alarmCheck = GUICtrlRead($alarmCheck1) ; Is the alarm active? $closeCheck = GUICtrlRead($closeCheck1) ; Should the tab close at a certain time? $closeHour = GUICtrlRead($closeHour1) ; Get the desired hour for the closing of the tab $closeMinute = GUICtrlRead($closeMinute1) ; Get the desired minute for the closing of the tab $closeAM_PM = GUICtrlRead($closeAM_PM1) ; Did the user choose AM or PM for the closing time? $daily = GUICtrlRead($daily1) ; Should this be a daily alarm? EndFunc ;==>GetSettings ; Function called when $openUserInterface is clicked Func ShowGUI() GUISetState(@SW_SHOW) ; Unhide the GUI TrayItemSetState($openUserInterface, 4) ; Uncheck the item EndFunc ;==>ShowGUI ; Function called by the "-" button and the OkayClick() function Func MinimizeGUItoTray() GUISetState(@SW_HIDE) ; Hide the GUI TraySetToolTip("Web Alarm App - click here to see user interface") EndFunc ;==>MinimizeGUItoTray #EndRegion ### Functions ###