Simple alarm (e-motiv)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
RUBn
Posts: 51
Joined: 27 Nov 2013, 05:12
Contact:

Simple alarm (e-motiv)

20 Aug 2015, 09:34

Features:
  • Sleep, Hibernate, Shut down with canceling possibility
  • Hour or Time from now (Snooze) ; both inputs update eachother
  • Traytip
  • Tooltip with update (to check how long remaining)
  • Some text to remember
e-motiv alarm.png
e-motiv alarm.png (1.87 KiB) Viewed 1959 times
ToDo (Once): Keep settings in ini file so alarm remains after (accidental) shutdown (when e.g. ahk = boot script)
Don't forget to update the sound file!

Code: Select all

;_________________Alarm by e-motiv.net
; TODO: Use text file in case of failure/ahk shutdown etc.. (iniwrite or so) ?
; TODO: Make better representation of different time ranges in tooltip
AlarmShutdown:
	if (TShut = 3)
		Shutdown, 9
	else	;Hibernate or Suspend
		DllCall("PowrProf\SetSuspendState", "int", TShut = 2?1:0, "int", 0, "int", 0)
return

AlarmEnd:
	SetTimer, AlarmEnd, Off 
	SetTimer, AlarmIconTipUpdate, Off
	if TShut
	{
		SoundPlay, C:\Users\Ruben\Sounds\140 Grime Synth D 01.wav
		WhichShut := TShut=3?"Shutdown":(TShut=2?"Hibernate":"Suspend")
		Menu,TRAY, Tip, %WhichShut% in 20 seconds. Trigger alarm again to cancel. `n %AlarmText%
		TrayTip,, %WhichShut% in 20 seconds.  Trigger alarm again to cancel.  `n %AlarmText%	
		SetTimer, AlarmShutdown, -20000
	}
	else
	{	
		NewIconTip := RegExReplace(A_IconTip, "\n*--[\s\S]*--", "") 
		Menu,TRAY, Tip, %NewIconTip%
		GoSub Alarm
	}	
return
	
Alarm:
	if TShut
	{
		SetTimer, AlarmShutdown, Off ; Cancel shutdown
		TShut = 0
		TrayTip,, %WhichShut% cancelled.
		Menu,TRAY, Tip
	}
	SoundPlay, C:\Users\Ruben\Sounds\140 Grime Synth D 01.wav
	IfWinNotExist, Alarm ahk_class AutoHotkeyGUI
	{
		gui, +AlwaysOnTop -Border 
		gui, font, s10, Verdana
		gui, add, text,ym+10 Center Section, Snooze: 
		
		gui, font, s20, Verdana
		gui, add, edit,xm+70 	ym	W45 R1 Center Number Limit2 gAlarmChangeTime  vTHours,	% THours?THours:00
		gui, add, text,x+2 yp+7, h
		gui, add, edit,x+7		ym	W45 R1 Center Number Limit2 gAlarmChangeTime vTMins, 	% TMins?TMins:00
		gui, add, text,x+2 , '	
		gui, add, edit,x+5		ym	W45 R1 Center Number Limit2 gAlarmChangeTime vTSecs, 	% TSecs?TSecs:00
		gui, add, text,x+2 , ''
		
		gui, font, s10, Verdana
		gui, add, text,xm y+30, Untill: 
		gui, font, s20, Verdana
		Gui, Add, DateTime,xm+70 yp-10 W160 Center gAlarmChangeSnooze vTTime, Time
		
		gui, font, s10, Verdana
		gui, Add, Edit, xm y+20 w300 R4 -VScroll vAlarmText, % AlarmText
		
		Gui, Add,Radio, xm+10 y+20 vTShut, Sleep
		Gui, Add,Radio, xp+80 yp, Hibernate
		Gui, Add,Radio, xp+90 yp, Shut down
		
		Gui, Add, Button,xm y+20 Center W300 R2 Default, Set!
	}
	; Fill in DateTime
	GoSub AlarmChangeTime
	gui, show, Restore, Alarm ;%A_Now%
    return
AlarmChangeTime:
	GuiControlGet,CF, FocusV
	IfEqual, CF, TTime, Return ; Don't loop since edit g-label gets triggered by script (AlarChangeSnooze)
	;MsgBox CurrentFocus: %CF%, A_Gui, A_GuiControl, A_GuiControlEvent,  A_GuiEvent, A_EventInfo : %A_Gui%, %A_GuiControl%, %A_GuiControlEvent%, %A_GuiEvent%, %A_EventInfo%
;todo: add time functions here as unpossible times become possible (25:61:61)
	GuiControlGet,THours
	GuiControlGet,TMins
	GuiControlGet,TSecs
	Temp:=A_Now
	Temp +=  %THours%,h
	Temp +=  %TMins%,m
	Temp +=  %TSecs%,s
	GuiControl,,TTime,%Temp%
	return
AlarmChangeSnooze:
	GuiControlGet,TTime 
	TTime -= ,s
	Temp2:=TTime // (60*60)
	;MsgBox %TTime%, %Temp2%
	GuiControl,,THours,%Temp2%
	Temp2:=Mod(TTime,60*60) // 60
	GuiControl,,TMins,%Temp2%
	Temp2:=Mod(Mod(TTime,60*60),60)
	GuiControl,,TSecs,%Temp2%
	return
AlarmIconTipUpdate:
	;Add icontip
	;MSgBox %TTimeIUpdate%  %TLeft% %A_IconTip%
	TLeft-=%TTimeIUpdate%
	TLeftHMS:=TLeft // (1000*60*60) . "h " . Mod(TLeft,1000*60*60) // (1000*60) . "m " . Mod(Mod(TLeft,1000*60*60),1000*60) // 1000 . "s"
	TTimeText2:=	" -- Alarm -- `n"
					 . "  " . (AlarmText ? AlarmText . "`n" : "")
					 . "  " . FTime . "`n"
					 . "  " . TLeftHMS . " from now  (± " . (TTimeIUpdate//1000) . " sec.)   `n"
					 . " --        -- "
	NewIconTip := RegExReplace(A_IconTip, " -- Alarm --[\s\S]* --        -- ", TTimeText2, Replaced) 
	If !Replaced
		NewIconTip := A_IconTip . (A_IconTip=""?"":"`n") . TTimeText2 
	;MsgBox Old: %A_IconTip%`nReplaced: %Replaced%`nNew: %NewIconTip%
	Menu,TRAY, Tip, %NewIconTip% 
	return
	
ButtonSet!:	
	Gui, Submit
	Gui, Destroy
	TStart:=A_Now
	TLeft:=((THours*60 + TMins)*60+TSecs)
	TTimeIUpdate:=TLeft//20*1000	; Distribute updater, but min. 1 sec.
	TLeft*=1000
	;MsgBox %THours%%TMins%%TSecs%
	;// Set one-time alarm timer
    SetTimer, AlarmEnd, %TLeft%	
	TTimeText:=THours . "h " . TMins . "m " . TSecs . "s"
	FormatTime, FTime, TTime, HH : mm : ss
	TrayTip,, Alarm Set for `n %FTime% `n %TTimeText% from now
	;//Set repeating icontip-update timer
	GoSub AlarmIconTipUpdate	; For icontip
	SetTimer, AlarmIconTipUpdate, %TTimeIUpdate%
	return
GuiEscape:
GuiClose:
	Gui, Destroy
	return

I am also: Image-motiv for professional, volunteer & open source (web) development
User avatar
RUBn
Posts: 51
Joined: 27 Nov 2013, 05:12
Contact:

Re: Simple alarm (e-motiv)

01 Oct 2023, 03:51


I am also: Image-motiv for professional, volunteer & open source (web) development
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: Simple alarm (e-motiv)

08 Oct 2023, 16:21

Please explain how to use this.

I downloaded the script and ran it expecting to see the GUI, instead my computer went into hibernation.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
RUBn
Posts: 51
Joined: 27 Nov 2013, 05:12
Contact:

Re: Simple alarm (e-motiv)

09 Oct 2023, 04:36

Any way you want. E.g.:

Code: Select all

#Include "alarm.ahk"
tray.add("Alarm", Alarm)
#t::Alarm()
If you use the old script, maybe it does that because of some v1 autohotkey update. I had this problem too during migration to v2 and fixed it. I don't know for v1 and not putting any more effort into it. Sorry.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 177 guests