Guest User

AutoHotkey Tray Icon Timer Script 2025-08

a guest
Aug 21st, 2025
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | Software | 0 0
  1. #NoEnv
  2. #SingleInstance, Force
  3. #Persistent
  4.  
  5. ; Initial state - icon is red
  6. iconState := "red"
  7. Menu, Tray, Icon, shell32.dll, 110 ; Red icon (red shield)
  8. Menu, Tray, Tip, Click to start timer (1 hour)
  9.  
  10. ; Make the tray icon clickable
  11. Menu, Tray, NoStandard
  12. Menu, Tray, Add, Start Timer, StartTimer
  13. Menu, Tray, Add, Exit, ExitApp
  14. Menu, Tray, Default, Start Timer
  15. Menu, Tray, Click, 1 ; Single click to activate
  16.  
  17. return
  18.  
  19. StartTimer:
  20. if (iconState = "red")
  21. {
  22. ; Set icon to green
  23. Menu, Tray, Icon, shell32.dll, 103 ; Green icon (green checkmark)
  24. iconState := "green"
  25. startTime := A_TickCount
  26.  
  27. ; Set timer for 1 hour (3600000 milliseconds)
  28. SetTimer, CheckTimer, 1000 ; Check every second
  29.  
  30. ; Update tooltip immediately
  31. Gosub, UpdateTooltip
  32. }
  33. return
  34.  
  35. CheckTimer:
  36. elapsedTime := A_TickCount - startTime
  37. if (elapsedTime >= 3600000) ; 1 hour = 3600000 ms
  38. {
  39. Menu, Tray, Icon, shell32.dll, 110 ; Red icon
  40. iconState := "red"
  41. SetTimer, CheckTimer, Off
  42. Menu, Tray, Tip, Timer completed! Click to restart.
  43. TrayTip, Timer Completed, The 1-hour timer has finished., 1, 1
  44. }
  45. else
  46. {
  47. ; Update the tooltip with remaining time
  48. Gosub, UpdateTooltip
  49. }
  50. return
  51.  
  52. UpdateTooltip:
  53. elapsedTime := A_TickCount - startTime
  54. remainingTime := 3600000 - elapsedTime
  55. remainingMinutes := Floor(remainingTime / 60000)
  56. remainingSeconds := Floor(Mod(remainingTime / 1000, 60))
  57.  
  58. if (remainingTime > 0)
  59. {
  60. tipText := remainingMinutes . "m " . remainingSeconds . "s remaining"
  61. Menu, Tray, Tip, %tipText%
  62. }
  63. return
  64.  
  65. ExitApp:
  66. ExitApp
  67. return
Advertisement
Add Comment
Please, Sign In to add comment